如何从UIMenuController中删除默认菜单项?

Per*_*uli 4 uimenucontroller ios

我创建了一个菜单UITableViewCell,这UIMenuController只有两个项目.但是当我运行它时,这个菜单显示了很多项目,似乎是ios默认菜单项,显示为截图:

在此输入图像描述

如何删除这些项目并只显示我定义的项目?谢谢.

这是我的代码:

- (id)initWithComment:(DSComment *)comment
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"comment"];

    UILabel *contentLabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 45, 300, 0)];
    contentLabel.text=comment.message;

    [self.contentView addSubview:contentLabel];
    return self;
}


- (BOOL) canBecomeFirstResponder {
    return YES;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self becomeFirstResponder];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    UIMenuItem *like = [[UIMenuItem alloc] initWithTitle:@"Like" action:@selector(like:)];
    UIMenuItem *reply = [[UIMenuItem alloc] initWithTitle:@"Replay" action:@selector(reply:)];

    [menu setMenuItems:[NSArray arrayWithObjects:like, reply, nil]];

    [menu setTargetRect:CGRectMake(0, 0, 0.0f, 0.0f) inView:self];
    [menu setMenuVisible:YES animated:YES];
}

axi*_*ixc 13

您需要覆盖canPerformAction:withSender:并返回NO您不想要的操作.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(_myCustomActionSelector:)) return YES;
    return NO;
}
Run Code Online (Sandbox Code Playgroud)