I create a menu in UITableViewCell
, this UIMenuController
just has two items. but when i runing it, this menu displayed many items, seems ios default menu item, be shown as the screenshot:
How can i remove those items and just display my defined item? thx.
here is my code:
- (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]; }
You need to override canPerformAction:withSender:
and return NO
for the actions you don't want.
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(_myCustomActionSelector:)) return YES;
return NO;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With