I\'m trying to add a menu item next to the \"copy\", \"paste\" items in a UITextView. I\'ve created a subclass of UITextView and copied the example from apple\'s docs here:
I was only able to create a custom menu item that is ALWAYS present in the popup menu, by doing the following:
- (void) setUpCustomMenu {
Class cls1 = NSClassFromString(@"UIMenuController");
Class cls2 = NSClassFromString(@"UIMenuItem");
if (cls1 && cls2)
if ([UIMenuController instancesRespondToSelector:@selector(setMenuItems:)]) {
UIMenuItem* item1 = [[UIMenuItem alloc] initWithTitle:@"My Menu Item" action:@selector(myMenuAction:)];
[UIMenuController sharedMenuController].menuItems = [NSArray arrayWithObjects:item1, nil];;
[item1 release];
}
}
This is called in the viewDidLoad of the view controller.
I'm still struggling to make this only show my menu item conditionally(if, for instance, there is something selected), by intercepting the event that summons up the menu controller. So far I wasn't able to do this.