IBActions and IBOutlets

We’ve already been introduced to .h (header) and .m (implementation) files through working with classes in Objective C. Now that we’ve progressed to creating simple apps, we can add .storyboard to that list. What is a storyboard file? The storyboard file stores your application’s user interface. I remember the first time I heard the term user interface and how awkward the term sounded to me. But the term is much less complicated than it sounds. It’s simply how we interact with our iPhones and iPads. It’s the buttons, labels, and text fields that we touch or slide on our iOS devices. We touch or slide buttons, labels and text fields on our phones when we want to retrieve information or send information. But what exactly is happening behind the scenes?

When working out of the Interface Builder, Xcode allows us to drag elements from the Library into our apps windows and views. We can see the app we are creating, but it won’t perform any actions until the connection is made between the User interface Objects and Xcode. Every UI object you create in Interface Builder must have a respective IBoutlet instant variable declared:

@interface FirstAppDelegate : NSObject <UIApplicationDelegate> {

UIWindow *window;

IBOutlet UIButton *aButton;

IBOutlet UILabel *helloLabel;


@property (nonatomic, retain) IBOutlet UIWindow *window;


After typing and saving the code above, you’d then return to the IB, press control while clicking the “First Delegate Icon”. This makes the connection window pop up. You should see the aButton and helloLabel IBOutlet instances in the First App Delegate list.From there, click and hold each outlet’s name and drag it to the corresponding US element in the view.

IBActions are special methods that are triggered by UI objects. When a button is pressed, it should call a method in your code. IBAction connections are made in the opposite direction as IBOutlets: you control-drag from your UI object to the orange class object icon.

IBOutlets and IBActions are keywords or indicators to Interface Builder of things that are available for it to “hook up” to. When your code is compiled by XCode, the IBOutlet keyword is removed entirely and the IBAction keyword is replaced by ‘void’.

A single golf clap? Or a long standing ovation?

By clapping more or less, you can signal to us which stories really stand out.