IPhone / iPad context menu

I am talking about the menu that appears when you select a block of text, it gives you the ability to cut / paste / copy. I figured out how to add another option to the menu, but if I add two or more options, it will say β€œmore” first. clicking on it will show all the options that I added. But is there a way to show all the options that I added in advance? without the menu item "more"?

+5
source share
2 answers

You need to use the UIMenuController . If you do not want Copy / Paste / Cut, you will include something like this in your method canPerformAction::

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
     if(action == @selector(someSelector:))
         return YES;
     else 
         return NO;
}

:

UIMenuItem *someAction = [[UIMenuItem alloc]initWithTitle:@"Something" action:@selector(doSomething:)];

UIMenuController *menu = [UIMenuController sharedMenuController];
menu.menuItems = [NSArray arrayWithObject:someAction];
[menu update];
+7

, UIMenuController. Copy/Paste/Cut/Delete/Select/SelectAll, UITextField UITextView:

- (BOOL)canPerformAction: (SEL)action withSender: (id)sender {
    BOOL answer = NO;
    if (action == @selector(item1)) {
        answer = YES;
    }
    if (action == @selector(item2)) {
        answer = YES;
    }
    return answer;
}

item1 item2 - UIMenuController.menuItems.

, UITextView, ", , " , UITextView.

- (BOOL) canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(paste:) || action == @selector(selectAll:)) {
            return YES;
    }
}
+1

All Articles