Information Technology Reference
In-Depth Information
Many IB objects include a Tag field, as shown in Figure 8.19. You can use this field to search a nib—or more
usually, a view in a nib—to find a matching object. For example, to find the button in the figure you might add
the following code to the view controller:
UIButton* theButtonImLookingFor
= (UIButton *)[self.view viewWithTag: 101010];
Typically you wouldn't do this for simple object updates—outlets are a better option. But tags can be very use-
ful when you work with table views. You can create cells dynamically and use tags to define how they're dis-
played—for example, to create cells with alternating colors. Tags can also be a good way to manage UI elements
when you generate them in code without using IB at all.
FIGURE 8.19
Defining a tag for a UI button
Sending messages between nibs
It's often useful to send messages between objects in different nibs. It isn't trivially easy to do this—some setting
up is always required. But it's not a difficult problem.
One common solution is to pass messages through First Responder. Optionally, you can add custom methods to
First Responder by clicking it, selecting the Attributes inspector, and adding an action as shown in Figure 8.20.
Add the action code to one of the classes in the responder chain. You can then link the custom action to but-
tons, menus, and other IB message-generating objects in the usual way.
Search WWH ::




Custom Search