Customizing Buttons and Making Connections
In this section we’ll use IB to add more interface
specifications to the Calculator.nib file,
including customizing buttons further and making several different
types of connections between objects. In order to make connections
which involve an object of the Controller class, we need a
representation of it in IB.
Instantiating (Creating an Instance of) the Controller Class
Creating the Controller class isn’t enough: we also need to create an object that is a member of this class, called an instance. Then we have to arrange for the numeric keypad of buttons in the Calculator window to send action messages to the instance whenever these buttons are clicked.
Make sure the Classes tab is displayed in IB’s Nib File window (titled “MainMenu.nib”), then select the Controller class (recall that it’s a subclass of NSObject). If you have trouble finding it, use the Search feature in the window.
Choose IB’s Classes → Instantiate Controller menu command.
This will create an icon called “Controller” under the Instances tab in the Calculator’s Nib File window, as shown in Figure 5-17 (IB automatically displays the Instances tab view). This icon represents an instance object of the Controller class — it can be used as the target object of action messages and also to initialize outlets. You can change the name from “Controller” to something else if you like — the name isn’t used for anything except your convenience in IB. Note the little circles with exclamation ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access