1
votes

I am implementing UIMenuController in my app to copy the text from custom tableviewCell.

I have two options to do that,

Option 1. Use tableviews shouldShowMenuForRowAtIndexPath delegates method

Option 2. Use custom UIMenuController. For which I have added (long press/double tap) gesture recognizer in my view.(I dont want to use didSelect for this for some other purpose)

What I actually want to do is - To display only copy option when I (long press/double tap) in tableView & to capture the indexPath of that tableView.

Problem with Option 1 is, it gives three option by default i.e. cut,copy,paste. Problem with Option 2 is, I am not able to get the index of the table as my long press Gesture recognizer method dont have the information of indexPath.

Is there any way I can get both things working (only copy option & getting indexPath on gesture).

1

1 Answers

0
votes

Option 2 will work. You can get the indexpath from long press method.

if (recognizer.state == UIGestureRecognizerStateBegan) {
    UITableView *cell = (UITableView *)recognizer.view;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

    UIMenuController *menu = [UIMenuController sharedMenuController];
    [menu setMenuItems:[NSArray arrayWithObjects:flag, approve, nil]];
    [menu setTargetRect:cell.frame inView:cell.superview];
    [menu setMenuVisible:YES animated:YES];
}

Remember the indexpath in your class and get access from that.