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

时间:2013-04-22 02:43:12

标签: ios uimenucontroller

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

enter image description here

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

这是我的代码:

- (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];
}

1 个答案:

答案 0 :(得分:12)

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

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