Information Technology Reference
In-Depth Information
Working with more advanced subclassing techniques
The following techniques are more specialized. You may not need to use them at all, but it's useful to know
they're available.
Adding User Defined Attributes to a subclass
If you subclass an object in the IB library, it automatically inherits that object's attributes. For example, a sub-
class of UIViewController includes options to set a default orientation and a status bar, a top bar, and a bottom
bar. You can't change these attributes, and you can't add further attributes of your own.
But not all Cocoa and Cocoa Touch objects have IB attributes—in fact most objects don't. How can you set ini-
tial values for these objects?
One option is to use code. But IB includes a User Defined Runtime Attributes feature, illustrated in Figure 8.9.
Objects without “official” attributes include a general purpose keypath, value, and type editor in the Identity in-
spector. You can add initial values/types here, and they're loaded and set when the nib loads.
Each item is equivalent to running the setValue: forKeyPath: method on an object. In the figure, the
example has the same effect as adding
[self setValue: @”Initial string” forKeyPath: @”myKeyPath”];
to an init method in the application delegate. Supported types include strings, localized strings, Booleans,
numbers, and nil .
Search WWH ::




Custom Search