Skip to content

Instantly share code, notes, and snippets.

@jamztang
Created June 28, 2012 08:08
Show Gist options
  • Save jamztang/3009826 to your computer and use it in GitHub Desktop.
Save jamztang/3009826 to your computer and use it in GitHub Desktop.
Fixing the "delete" menu for UITableView shouldShowMenuForRowAtIndexPath
// Quick Hack to enable delete menu item
@implementation UITableViewCell (Addition)
- (void)delete:(id)sender {
// We define delete: method so that our UIMenuController delete item shows up
id nextResponder = self.nextResponder;
for (;;nextResponder = self.nextResponder) {
if ([nextResponder isKindOfClass:[UITableView class]]) {
UITableView *tableView = nextResponder;
NSIndexPath *indexPath = [tableView indexPathForCell:self];
if (indexPath) {
[[tableView delegate] tableView:tableView
performAction:@selector(delete:)
forRowAtIndexPath:indexPath
withSender:sender];
break;
}
}
}
}
@end
@ryanmasondavies
Copy link

Thanks for this. Seems more in line with Apple's 'right way' of implementing UIMenuController on a table than manually adding a long press gesture recognizer.

@jamztang
Copy link
Author

@macrococoa You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment