What are Actions?

Actions are methods that are part of your controller class and are declared with a special keyword, IBAction.  This keyword tells Interface Builder that this is an action and can be triggered by a control.  In short if you want to have interface objects in the nib (like buttons) trigger methods in the controller class then you would use special methods called Actions.

Example declaration of an action method:

- (IBAction)doSomething:(id)sender;

  • -(IBAction) = the return type
  • doSomething: = name of the action
  • (id) = argument
  • sender; = argument name

The name of the action can be anything you want but must have a return type of IBAction, which is the same as declaring a return type of -(void).  It just says that action methods do not return a value.

Usually an action method will take one argument and is typically defined as id and given a name of sender.  (id)sender; is not always necessary when declaring an action method but is typically used all the time.  The purpose of (id)sender; is to contain a reference to the control that has triggered the action method.

This entry was posted in iPhone Development. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>