Information Technology Reference
In-Depth Information
Figure 8.7 shows why. If you select the view in the nib file and look at the entry in the Class menu in the top
pane of the Identity Inspector, you see it's set to UIView . When the application launches, it ignores the new
code because the nib file still creates an instance of the original unmodified version of UIView .
FIGURE 8.7
In subclassing UIView, the final step tells IB that the view is now an instance of the new IBView subclass. This
runs the code in the subclass and enables your new customized features.
To fix this, we tell IB to create an instance of the new subclass, also known as assigning the subclass. Click the
top-right menu as shown in the figure, and scroll down until you find IBView in the list. Click it to assign it.
Now the nib file is set up correctly, and it loads the new subclass on launch.
Figure 8.8 shows the result. The UIView draws a colored gradient behind the other items.
TIP
Whenever you select an object in the IB editor, the class identity list is updated to show all its valid subclasses.
This listing is indiscriminate, and you can do nonsensical things such as assigning UIWindow as the designated sub-
class of your new UIView . In most applications, you can ignore most of the items in the list and simply look for
your newly added subclass.
FIGURE 8.8
Running the subclassed view. The code added to the subclass creates a gradient fill.
Search WWH ::




Custom Search