Why my UIMenuItems are showing in the 'more' section of UIMenuController?
I am showing UIMenuController while a table cell is long pressed. I am using the code below.
- (void)onCellLongPressed:(UILongPressGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateRecognized) {
ContactTableViewCell *cell = (ContactTableViewCell *)recognizer.view;
[cell becomeFirstResponder];
UIMenuIte开发者_开发百科m *item1 = [[UIMenuItem alloc] initWithTitle:@"ME" action:@selector(setMe)];
UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"YOU" action:@selector(setYou)];
[theMenu setMenuItems:[NSArray arrayWithObjects:item1, item2, nil]];
UIMenuController *theMenu = [UIMenuController sharedMenuController];
[theMenu setTargetRect:[cell frame] inView:[self tableView]];
[theMenu setMenuVisible:YES animated:YES];
}
}
My problem is, When I long press a cell, menu pops up with all the default menu items. My menu items "SAVE" and "DELETE" are not showing when the menu pops up. They are showing when I select the "more" menu. I posted the screen shots below.
SCREEN SHOT 1: Menu that pops up when I long press a cell.
SCREEN SHOT 2: Menu when I press the "more" menu item in SCREEN SHOT 1.
I want the menu in SCREEN SHOT 2 to open when I long press a cell.
- What wrong am I doing here?
- What am I missing here?
- What I should do to make it work?
To disable the default items, you need the canPerformAction:withSender:
method to return NO. Which means that you need for the objects in the responder chain to not perform the requested actions, or a custom implementation of the method.
精彩评论