Information Technology Reference
In-Depth Information
ally. Similarly, user interactions are copied to a bound property automatically. Bindings are an alternative to
outlets, with extra features that make them ideal for use with data collection objects such as arrays. Bindings
are not available in iOS.
Understanding nib files
The files created by IB are called nib files . Both iOS and OS X applications load a single default nib file when
they launch. This file is specified in the application's plist. But nib files are often linked and nested, so this nib
file may (and usually does) load another nib file, which may load yet another nib file, and so on.
CAUTION
An important feature missing from IB is an overall view of the hierarchy, showing how nib files are nested and
chained. IB tells you that an object will load another nib, but it doesn't try to show you a complete load tree.
As the nib files load, the objects defined inside them are created automatically. If they're part of the UI, they ap-
pear on screen. If they're not, they're loaded into memory. It's important to understand that you can use IB to
instantiate objects in this way.
Objects created by the IB loading system are identical to objects created using the standard Objective-C alloc
and init methods. There are two critical differences. The first is that nib files include preset default properties,
such as size, color, and position. The other is that the object's init method isn't called, so you must add extra
code to allow for this.
In practice, you can create a complete UI without using IB at all, by calling alloc and init to create a list of
objects in your code as the application starts, setting up useful defaults, and linking the objects into the applica-
tion's view hierarchy.
Some developers prefer to use this approach, and it's a valid option for UIs with unusual features. For example,
if you want to add custom pop-up menus with unique animations and other special features, it's easier to create
them in code.
IB is ideal for simpler interfaces that use Apple's standard kit of UI objects. Beginners typically create simple in-
terfaces that use these objects as is, using IB as a layout and preview tool that controls the aesthetic elements of
the interface—object justification and alignment, centering, and so on.
More advanced developers use IB to customize objects. Some objects are easy to customize; for example, it's
fairly easy in iOS to replace the standard button graphics with custom button art. Other objects are more chal-
lenging. But it's a key feature of the nib system that it has two possible applications. In addition to the default
nib files loaded at launch, you can also use it to create independent nib files that can be loaded on demand by
any object that needs them. For example you can load UIs on demand as you swap views, or load different ob-
ject collections at different stages in a game.
NOTE
The extension of nib files is .xib . Historically, .nib was an acronym of NeXT Interface Builder . From IB 3.0 on,
nib files were implemented with XML. The extension was changed, but the old name remained.
Search WWH ::




Custom Search