forked from moredip/Frank
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Distinguish edit delete from swipe delete.
- Loading branch information
Showing
8 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@interface UITableViewCell (ConfirmDeletionButton) | ||
|
||
-(BOOL)FEX_isShowingDeleteButton; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|