Action Methods are declared with a special keyword, IBAction, which tells Interface Builder that tis is a action method, and can be triggered by a control objects. Typically, the declaration of an action method is look like this:
- (IBAction)actionMethod:(id)sender;
As a example, a button will be used to generate a Touch Up event, to trigger a action method, actionMethod() in controller class.
modify the header file, in form of xxxViewController.h, to add declaration of the Action Method.
@interface xxxViewController : UIViewController {
}
- (IBAction)actionMethod:(id)sender;
@end
Define the body of the Action Method inside definition file, xxxViewController.m.
#import "helloiphoneViewController.h"
@implementation helloiphoneViewController
-(IBAction)actionMethod:(id)sender{
//do something...
}
Save your works.
Connect IBAction in INterface Builder:
Double click on the xxxViewController.xib in Groups & Files pane, under Resources folder, to start Interface Builder.
Drag the control you want from Library to View pane, if you haven't placed it.
Open the Connection Inspector from Tools on top menu.
Click on to select the control object you want to connect the IBAction.
A list of available events will be listed inside the Connection Inspector. Select the event you expect to trigger the action, drag the circle on the right of it, to over File's Owner on xib pane.
Release mouse button, the available action methods will be listed, click to select the right one.
Connection Inspector will be updated to have the new connection.
Save your works.
that's.




