gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 05:03:21 24 4
gpt4 key购买 nike

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

enter image description here

我怎样才能删除那些项目并只显示我定义的项目?谢谢。

这是我的代码:

- (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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com