info[at]theconspiracynyc.com
echodesignlab | bytedissident | wheresyourmachine | projects | theory | tutorials | 
HOME
WORK
CLIENTS
SERVICES
IOO
COMPANY INFO
CONTACT
PRODUCTS
GUIDELINES
 

IBActions / Connecting UI Objects Part 2

November 22, 2010 04:48 pm
Posted By: bytedissident

This is part 2 of my Interface Builder tutorial. In part I outlined the 3 step process to connecting a UI element added via Interface Builder to your view controller via the creation of an IBOutlet prefaced property. In this tutorial we will look at how to add a target and call a method from that UI element (UIButton) with an IBAction.

As with an IBOutlet we need a way to let Interface Builder find the method you want to add a target and action to. This is done simply in the following steps:

Step 1:

Add a method to your view controller. Lets call it doSomething for the sake of this tutorial. In order for Interface Builder to connect to this we will need to make this method return an IBAction.

In your header file add:

-(IBAction)doSomething;

In your implementation file add:

-(IBAction)doSomething
{
NSLog(@"HEllO");
}

Step 2:

In interface builder ctrl-click on your button and drag a connection from your button to your files owner and choose your method from the menu (screen shot 2) and that’s it. Your connected. Test your code and be on your way.

ibaction1

Ibaction2Download Code