I have been implemented an UIMenuItem to show by long-pressing an item on a TableViewController that is an element of a UITabBarController. I did that like below
- (void)viewDidLoad
{
resendMenuItem = [[UIMenuItem alloc] initWithTitle:@"Kirim Ulang" action:@selector(resend:)];
[[UIMenuController sharedMenuController] setMenuItems: @[resendMenuItem]];
[[UIMenuController sharedMenuController] update];
}
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
selectedIndex = indexPath.row;
return (action == @selector(resend:));
}
- (BOOL)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
selectedIndex = indexPath.row;
return YES;
}
-(BOOL) canPerformAction:(SEL)action withSender:(id)sender {
return (action == @selector(resend:));
}
-(BOOL)canBecomeFirstResponder {
return YES;
}
/// this methods will be called for the cell menu items
-(void) resend: (id) sender
{
// do something
}
Initially the menu appears well. However after switching to other tab in a UITabBarController then switch back again to UITableViewController, the menu becomes not to appear if i long-press it. Why?