Im talking about the menu that shows up when you select a block of text it gives you the option to cut/paste/copy. I figured out how to add one more option to the menu, but
You need to use a UIMenuController. If you don't want Copy/Paste/Cut, you'll include something like this in your canPerformAction:
method:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if(action == @selector(someSelector:))
return YES;
else
return NO;
}
Creating a new menu item looks like this:
UIMenuItem *someAction = [[UIMenuItem alloc]initWithTitle:@"Something" action:@selector(doSomething:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
menu.menuItems = [NSArray arrayWithObject:someAction];
[menu update];
I assume your talking about UIMenuController. If you don't want to see Copy/Paste/Cut/Delete/Select/SelectAll you will need to add the following code to your UITextField
's or UITextView
's delegate:
- (BOOL)canPerformAction: (SEL)action withSender: (id)sender {
BOOL answer = NO;
if (action == @selector(item1)) {
answer = YES;
}
if (action == @selector(item2)) {
answer = YES;
}
return answer;
}
Where item1
and item2
are the names of the objects in UIMenuController.menuItems
.
In my experience if you are using a UITextView
the Copy, Paste, Cut and Select All menu items will remain, in this case add the following code to a subclass of UITextView
.
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(paste:) || action == @selector(selectAll:)) {
return YES;
}
}