How do you REALLY remove Copy from UIMenuController

后端 未结 6 1248
悲&欢浪女
悲&欢浪女 2020-12-04 22:31

There apparently used to be an easy way to prevent the \"More...\" label from appearing in UIMenuController when you added more than one custom menu item. You just had to re

6条回答
  •  無奈伤痛
    2020-12-04 23:04

    The technique you linked to still seems to work. I implemented a UIWebView subclass with these methods, and only the A and B items appeared.

    + (void)initialize
    {
        UIMenuItem *itemA = [[UIMenuItem alloc] initWithTitle:@"A" action:@selector(a:)];
        UIMenuItem *itemB = [[UIMenuItem alloc] initWithTitle:@"B" action:@selector(b:)];
        [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:itemA, itemB, nil]];
        [itemA release];
        [itemB release];
    }
    
    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
        BOOL can = [super canPerformAction:action withSender:sender];
        if (action == @selector(a:) || action == @selector(b:))
        {
            can = YES;
        }
        if (action == @selector(copy:))
        {
            can = NO;
        }
        NSLog(@"%@ perform action %@ with sender %@.", can ? @"can" : @"cannot", NSStringFromSelector(action), sender);
        return can;
    }
    

提交回复
热议问题