Graphics Programs Reference
In-Depth Information
For the More Curious: UIMenuController and
UIResponderStandardEditActions
The
UIMenuController
is typically responsible for showing the user an “edit” menu
when it is displayed; think of a text field or text view when you press and hold. Therefore,
an unmodified menu controller (one that you don't set the menu items for) already has de-
fault menu items that it presents, like
Cut
,
Copy
, and other familiar friends. Each item has
an action message wired up. For example,
cut:
is sent to the view presenting the menu
controller when the
Cut
menu item is tapped.
All
UIResponder
s implement these methods, but, by default, these methods don't do
anything. Subclasses like
UITextField
override these methods to do something appro-
priate for their context, like cut the currently selected text. The methods are all declared in
the
UIResponderStandardEditActions
protocol.
If you override a method from
UIResponderStandardEditActions
in a view, its
menu item will automatically appear in any menu you show for that view. This works be-
cause the menu controller sends the message
canPerformAction:withSender:
to
its view, which returns
YES
or
NO
depending on whether the view implements this method.
If you want to implement one of these methods but
don't
want it to appear in the menu, you
can override
canPerformAction:withSender:
to return
NO
.
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
return NO;
// The superclass' implementation will return YES if the method is in the .m file
return [super canPerformAction:action withSender:sender];
}