How to remove default menu items from UIMenuController?

I create a menu in a UITableViewCell , this UIMenuController has only two elements. but when I run it, a lot of elements are displayed in this menu, it seems that the ios menu item is displayed as a screenshot by default:

enter image description here

How can I remove these elements and just display my specific element? 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];
 }
+4
source share
1 answer

You need to override canPerformAction:withSender: and return NO for actions you don't want.

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

All Articles