Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Distinguish edit delete from swipe delete.
  • Loading branch information
dhemery committed May 25, 2012
1 parent 2bc9e62 commit d827884
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Frank.xcodeproj/project.pbxproj
Expand Up @@ -164,6 +164,8 @@
D6FA01B714283C4F00576AE1 /* FranklyProtocolHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AE0 /* FranklyProtocolHelper.m */; };
D6FA01B714283C4F00576AE3 /* FranklyProtocolHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AE2 /* FranklyProtocolHelper.h */; };
D6FA01B714283C4F00576AE5 /* KIFTestStep.m in Sources */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AE4 /* KIFTestStep.m */; };
D6FA01B714283C4F00576AEB /* UITableViewCell+TappableConfirmationButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AEA /* UITableViewCell+TappableConfirmationButton.h */; };
D6FA01B714283C4F00576AED /* UITableViewCell+TappableConfirmationButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AEC /* UITableViewCell+TappableConfirmationButton.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -344,6 +346,8 @@
D6FA01B714283C4F00576AE0 /* FranklyProtocolHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FranklyProtocolHelper.m; sourceTree = "<group>"; };
D6FA01B714283C4F00576AE2 /* FranklyProtocolHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FranklyProtocolHelper.h; sourceTree = "<group>"; };
D6FA01B714283C4F00576AE4 /* KIFTestStep.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = KIFTestStep.m; path = lib/KIF/Classes/KIFTestStep.m; sourceTree = "<group>"; };
D6FA01B714283C4F00576AEA /* UITableViewCell+TappableConfirmationButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UITableViewCell+TappableConfirmationButton.h"; path = "src/UITableViewCell+TappableConfirmationButton.h"; sourceTree = "<group>"; };
D6FA01B714283C4F00576AEC /* UITableViewCell+TappableConfirmationButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UITableViewCell+TappableConfirmationButton.m"; path = "src/UITableViewCell+TappableConfirmationButton.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -394,6 +398,8 @@
08FB77AEFE84172EC02AAC07 /* src */ = {
isa = PBXGroup;
children = (
D6FA01B714283C4F00576AEC /* UITableViewCell+TappableConfirmationButton.m */,
D6FA01B714283C4F00576AEA /* UITableViewCell+TappableConfirmationButton.h */,
C1C3CCBE156BCF3500AEE136 /* FEXTappableConfirmationButton.h */,
C1C3CCBF156BCF3500AEE136 /* FEXTappableConfirmationButton.m */,
D6FA01B714283C4F00576ADE /* KeyboardCommand.h */,
Expand Down Expand Up @@ -735,6 +741,7 @@
D6FA01B714283C4F00576ADF /* KeyboardCommand.h in Headers */,
D6FA01B714283C4F00576AE3 /* FranklyProtocolHelper.h in Headers */,
C1C3CCC0156BCF3500AEE136 /* FEXTappableConfirmationButton.h in Headers */,
D6FA01B714283C4F00576AEB /* UITableViewCell+TappableConfirmationButton.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -903,6 +910,7 @@
D6FA01B714283C4F00576AE1 /* FranklyProtocolHelper.m in Sources */,
D6FA01B714283C4F00576AE5 /* KIFTestStep.m in Sources */,
C1C3CCC1156BCF3500AEE136 /* FEXTappableConfirmationButton.m in Sources */,
D6FA01B714283C4F00576AED /* UITableViewCell+TappableConfirmationButton.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
20 changes: 20 additions & 0 deletions example/Controls/features/step_definitions/table_deletion.rb
Expand Up @@ -8,3 +8,23 @@
delete_control_selector = "view:'UITableViewCell' view marked:'#{tvc_mark}' parent view:'UITableViewCell' view:'UITableViewCellEditControl'"
touch delete_control_selector
end

When /^I should see the confirm deletion button$/ do
check_element_exists("view:'UITableViewCellDeleteConfirmationControl'")
end

When /^I should not see the confirm deletion button$/ do
check_element_does_not_exist("view:'UITableViewCellDeleteConfirmationControl'")
end

Then /^I should not see an "(.*?)" button$/ do |button_mark|
check_element_does_not_exist("button marked:'#{button_mark}'")
end

Then /^I should see an "(.*?)" button$/ do |button_mark|
check_element_exists("button marked:'#{button_mark}'")
end

Then /^I should not see a "(.*?)" button$/ do |button_mark|
check_element_does_not_exist("button marked:'#{button_mark}'")
end
29 changes: 24 additions & 5 deletions example/Controls/features/ui_table.feature
Expand Up @@ -14,22 +14,41 @@ Scenario: Checking for elements in a table

Scenario: delete with swipe
When I swipe "Larry" leftwards
Then I should see "Delete"
Then I should see the confirm deletion button

When I confirm table cell deletion
Then I should not see "Delete"
Then I should not see the confirm deletion button
And I should not see "Larry"
But I should see "Curly"
And I should see "Moe"

Scenario: delete with edit mode
When I touch "Edit"
And I touch the delete edit control for the table view cell "Moe"
Then I should see "Delete"
Then I should see the confirm deletion button

When I confirm table cell deletion
Then I should not see "Delete"

Then I should not see the confirm deletion button
And I should not see "Moe"
But I should see "Larry"
And I should see "Curly"

Scenario: delete with swipe ends edit mode
When I swipe "Larry" leftwards
Then I should see a "Done" button
And I should not see an "Edit" button

When I confirm table cell deletion
Then I should see an "Edit" button
Then I should not see a "Done" button

Scenario: deleting in edit mode does not end edit mode
When I touch "Edit"
Then I should see a "Done" button
And I should not see an "Edit" button

When I touch the delete edit control for the table view cell "Moe"
And I confirm table cell deletion
Then I should see a "Done" button
And I should not see an "Edit" button
Binary file modified gem/frank-skeleton/libFrank.a
Binary file not shown.
Binary file modified gem/frank-skeleton/libShelley.a
Binary file not shown.
27 changes: 21 additions & 6 deletions src/FEXTappableConfirmationButton.m
@@ -1,26 +1,41 @@
#import <ObjC/runtime.h>
#import "FEXTappableConfirmationButton.h"
#import "UITableViewCell+TappableConfirmationButton.h"

void FEX_confirmDeletion(id self, SEL _cmd) {
UITableViewCell *cell = (UITableViewCell *)[(UIView *) self superview];

// If the cell is showing a delete button, then the
// user entered edit mode by tapping the table's Edit
// button. Otherwise, the user entered edit mode by
// swiping the cell. If the user entered edit mode by
// swiping, we need to end edit mode after confirming
// deletion. If we entered edit mode by tapping the
// Edit button, we will leave it to the user to end
// edit mode.
BOOL shouldEndEditing = ![cell FEX_isShowingDeleteButton];

void FEX_touchConfirmDeletionButton(id self, SEL _cmd) {
UIView *this = (UIView *)self;
UITableViewCell *cell = (UITableViewCell *)[this superview];
UITableView *tableView = (UITableView *)[cell superview];
id <UITableViewDataSource> dataSource = [tableView dataSource];
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
[dataSource tableView:tableView
commitEditingStyle:UITableViewCellEditingStyleDelete
forRowAtIndexPath:indexPath];
[tableView setEditing:NO animated:YES];

if (shouldEndEditing) {
[tableView setEditing:NO animated:YES];
[tableView.delegate tableView:tableView didEndEditingRowAtIndexPath:indexPath];
}
}

@implementation FEXTappableConfirmationButton

+ (void)install {
Class confirmationButtonClass = NSClassFromString(@"UITableViewCellDeleteConfirmationControl");
SEL tapSelector = NSSelectorFromString(@"touch");
char *const voidNoArgsType = "v@:";

class_replaceMethod(confirmationButtonClass, tapSelector, (IMP) FEX_touchConfirmDeletionButton, voidNoArgsType);
class_replaceMethod(confirmationButtonClass, NSSelectorFromString(@"tap"), (IMP) FEX_confirmDeletion, voidNoArgsType);
class_replaceMethod(confirmationButtonClass, NSSelectorFromString(@"touch"), (IMP) FEX_confirmDeletion, voidNoArgsType);
}

@end
6 changes: 6 additions & 0 deletions src/UITableViewCell+TappableConfirmationButton.h
@@ -0,0 +1,6 @@
@interface UITableViewCell (ConfirmDeletionButton)

-(BOOL)FEX_isShowingDeleteButton;

@end

14 changes: 14 additions & 0 deletions src/UITableViewCell+TappableConfirmationButton.m
@@ -0,0 +1,14 @@

@implementation UITableViewCell (ConfirmDeletionButton)

-(BOOL)FEX_isShowingDeleteButton {
Class deleteButtonClass = NSClassFromString(@"UITableViewCellEditControl");
for(UIView *subview in [self subviews]) {
if ([subview isKindOfClass:deleteButtonClass]) {
return YES;
}
}
return NO;
}
@end

0 comments on commit d827884

Please sign in to comment.