I'm using the new customization abilities of the UIMenuController to add things other than "Copy" to the menu for cut&paste into a webview.
What I do is getting the reference to the shared UIMenuController, setting my NSArray of UIMenuItems into the menuItems, and everything work fine as long as I add a single item. For instance I see [COPY|FOOBAR].
Instead if I try adding more than a single item, what happen is that I see [COPY|MORE], if I press into MORE than finally the other items will show up.
Is possible to show directly [COPY|FOO|BAR|THREE|FOUR] instead? I saw a few applications that are able to do this, notably iBooks.
Any help very appreaciated, thank you.
Cheers, sissensio
fluXa's answer is actually correct, but I dont think it was very clear.
The issue is that when adding custom UIMenuItem objects to the shared menu controller ([UIMenuController sharedMenuController]), only the first custom UIMenuItem will be shown on the initial display of the menu. The remaining custom menu items will be shown if the user taps "More...".
However, if the menu doesn't include any built-in system menu items (copy:, paste:, etc), the initial menu display will show all custom menu items and no "More..." item.
If you need to include the built-in system items, simply add custom UIMenuItems having the same title but with a different selector. ( myCopy: vs. copy: )
Essentially it boils down to NOT calling the default implementation of canPerformAction:withSender:, explicitly handling all custom menu items, and returning NO for all other (system-supplied) menu items:
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender
{
if ( action == @selector( onCommand1: ) )
{
// logic for showing/hiding command1
BOOL show = ...;
return show;
}
if ( action == @selector( onCommand2: ) )
{
// logic for showing/hiding command2
BOOL show = ...;
return show;
}
if ( action == @selector( onCopy: ) )
{
// always show our custom "copy" command
return YES;
}
return NO;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With