开发者

Why my UIMenuItems are showing in the 'more' section of UIMenuController?

开发者 https://www.devze.com 2023-02-02 09:13 出处:网络
I am showing UIMenuController while a table cell is long pressed. I am using the code below. - (void)onCellLongPressed:(UILongPressGestureRecognizer *)recognizer {

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.

Why my UIMenuItems are showing in the 'more' section of UIMenuController?

SCREEN SHOT 2: Menu when I press the "more" menu item in SCREEN SHOT 1.

Why my UIMenuItems are showing in the 'more' section of UIMenuController?

I want the menu in SCREEN SHOT 2 to open when I long press a cell.

  1. What wrong am I doing here?
  2. What am I missing here?
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消