作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 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];}
最佳答案
您需要覆盖 canPerformAction:withSender:
并为您不想要的操作返回 NO
。
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(_myCustomActionSelector:)) return YES;
return NO;
}
关于ios - 如何从 UIMenuController 中删除默认菜单项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16138650/
我是一名优秀的程序员,十分优秀!