Description
Hi,
I have implemented the following 3 delegate methods for UITableView to show a copy menu item to copy a cell.
- (void)tableView:(UITableView*)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
if (action == @selector(copy:)) {
SWTableViewCell *cell = (SWTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
self.copiedName = cell.textLabel.text;
[self.items insertObject:self.copiedName atIndex:indexPath.row];
NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
[self.tableView beginUpdates];
[tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView endUpdates];
}
}
- (BOOL)tableView:(UITableView*)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
return YES;
}
return NO;
}
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath*)indexPath {
return YES;
}
This works just fine in normal UITableViewCells. But when using SWTableViewCell, that little copy menu doesn't show up. I put breakpoints at each of these methods but none of them gets fired even.
Can anyone please tell me why this is happening and possibly a way to fix this?
Many thanks.
EDIT 1: I looked through the source files in SWTableViewCell and it seems there's a special long press gesture recognizer class. Since the copy menu appears when long pressing on a cell too, the cause might be this long press gesture is interfering with that, I guess? Is there any way to turn off the SWLongPressGestureRecognizer?
EDIT 2: I commented out the following code block from SWTableViewCell.m file and as expected my issue was resolved.
self.longPressGestureRecognizer = [[SWLongPressGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewPressed:)];
self.longPressGestureRecognizer.cancelsTouchesInView = NO;
self.longPressGestureRecognizer.minimumPressDuration = kLongPressMinimumDuration;
self.longPressGestureRecognizer.delegate = self;
[self.cellScrollView addGestureRecognizer:self.longPressGestureRecognizer];
But I'd rather do this in a non-hackish way because I'm not sure weather that long press is an essential part for the control to work. So my question still stands.