What are Outlets?

When building an iPhone app there comes a need for the code you write to interact with the elements you create in Interface Builder, this is called an Outlet.

The Outlet is and instance variable, and our controller class can refer to objects in the nib by using Outlets.  Outlets are used to effect objects in your nib such as text labels, buttons and so on.  By declaring an outlet and connecting that outlet to an object in the nib, you could use the outlet from within your code to change any object in your nib.

The Outlet is declared using (IBoutlet)

Example:

@property (nonatomic, retain) IBOutlet UILabel *statusText;

The IBOutlet keyword is defined like this:

#ifndef IBOutlet
#define IBOutlet
#endif

IBOutlet does nothing as far as the compiler is concerned. Its purpose is to act as an indicator or hint to tell Interface Builder that this is an instance variable that were going to use to connect to an object in the nib. At any time if you want an instance variable to connect to an object in the nib then it must be preceded by the IBOutlet keyword.

Connections made from your code to the nib must use these instance variables.

This entry was posted in iPhone Development and tagged , . 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>