4

我在 中创建了一个菜单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];
    回归自我;
}


- (BOOL) canBecomeFirstResponder {
    返回是;
}

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

    [菜单 setMenuItems:[NSArray arrayWithObjects:like, reply, nil]];

    [菜单 setTargetRect:CGRectMake(0, 0, 0.0f, 0.0f) inView:self];
    [菜单 setMenuVisible:YES 动画:YES];
}
4

1 回答 1

13

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

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(_myCustomActionSelector:)) return YES;
    return NO;
}
于 2013-04-22T03:01:02.363 回答