views:

41

answers:

3

Where can I find the method signature for callback methods in built-in classes like UIGestureRecognizer or UIMenuItem etc?

e.g., documentation states for UIMenuItem:

initWithTitle:action:
Creates and returns a menu-item object initialized with the given title and action.

-(id)initWithTitle:(NSString )title action:(SEL)action

Parameters
title
The title of the menu item.
action
A selector identifying the method of the responder object to invoke for handling the command represented by the menu item.
Return Value
An initialized UIMenuItem object, or nil if there was a problem creating the object.

How do I know what parameter 'action' may receive?

A: 

Action can be any selector. You can make a selector by using @selector(...) or NSSelectorFromString(...).

Alexsander Akers
That doesn't answer the question of what parameters the action method can expect to receive.
Peter Hosey
It usually has an `(id) sender` method, unless otherwise specified.
Alexsander Akers
+1  A: 

'action' is a convention in Cocoa Touch/UIKit : Target-Action in UIKit

Actions can have any of the following three signatures in UIKit:

- (void)action
- (void)action:(id)sender
- (void)action:(id)sender forEvent:(UIEvent *)event
Art Gillespie
UIKit [differs somewhat](http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW44) in convention.
Georg Fritzsche
That's for Cocoa; in Cocoa Touch, the action method can take any of three forms, all of which are documented here: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html%23//apple_ref/doc/uid/TP40002974-CH7-SW44
Peter Hosey
+4  A: 

See the documentation for the Target-Action Mechanism in UIKit. Specifically it mentions the following:

In contrast with the Application Kit, where an action method may have only one or perhaps two valid signatures, the UIKit framework allows three different forms of action selector:

  • - (void)action
  • - (void)action:(id)sender
  • - (void)action:(id)sender forEvent:(UIEvent *)event
Georg Fritzsche