我已经实现了一个 UIMenuItem,通过长按 TableViewController 上的一个项目来显示,该项目是 UITabBarController 的一个元素。我像下面那样做
- (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
}
最初菜单看起来不错。但是,在切换到 UITabBarController 中的其他选项卡然后再次切换回 UITableViewController 后,如果我长按它,菜单就不会出现。为什么?