实际上,我对 iOS7 中用于在 UITableView 上显示自定义上下文菜单的更改有点困惑。
我的代码如下:
- (void)viewDidLoad {
UIMenuItem *deleteAction = [[UIMenuItem alloc]initWithTitle:NSLocalizedString(@"Delete", nil) action:@selector(delete:)];
UIMenuItem *renameAction = [[UIMenuItem alloc]initWithTitle:NSLocalizedString(@"Rename", nil) action:@selector(rename:)];
UIMenuController* mc = [UIMenuController sharedMenuController];
mc.menuItems = [NSArray arrayWithObjects: renameAction, deleteAction, nil];
[mc setTargetRect:CGRectMake(50.0, 50.0, 0, 0) inView:self.view];
[mc setMenuVisible:YES animated:YES];
[mc setMenuItems:@[deleteAction, renameAction]];
[self becomeFirstResponder];
-(void)tableView:(UITableView*)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender{
}
-(BOOL)tableView:(UITableView*)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender {
if (tableView != nil && indexPath != nil)
{
if (action == @selector(delete:)) {
return YES;
}
if (action == @selector(rename:)) {
return YES;
}
}
return NO;
}
-(BOOL)tableView:(UITableView*)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath*)indexPath {
return YES;
}
我的问题是,在 iOS 的预览版中一切正常。如果用户长按表格视图的单元格,则会出现自定义上下文菜单,但在 iOS7 中没有任何反应。方法被调用但没有显示。