wiki:AppleCurrencyConverterBuildingUserInterfaceWithTigerAddClasses

Version 7 (modified by mikel, 6 years ago) (diff)

--

Set Up the Classes Used In the User Interface

The visual elements of your application's user interface are all ready now. The last thing you must do is create descruptions of any custom classes used by the application when users interact with the interface.

When a user clicks the "Convert" button, it should send a message to an instance of a custom class that causes the conversion to take place, and the result to be displayed in the "Amount" field. In order for the application to connect the user interface to objects that perform these actions, you must add descriptions of your classes and instances to the nibfile. Fortunately, InterfaceBuilder can create class and instance descriptions and save them in the nibfile for you.

ConverterController

ConverterController is the controller class; an instance of it handles messages sent when the "Convert" button is pressed. Create a description of the ConverterController class, and then create an instance of it.

  1. In InterfaceBuilder's "CurrencyConverter.nib" window, click the "Classes" tab. The window shows a browser view of all available Objective-C classes:

Classes in !InterfaceBuilder

  1. Control-click the "NSObject" entry in the browser, and choose "Subclass NSObject" from the popup menu. InterfaceBuilder creates a new entry initially called "MyObject". Change the name from "MyObject" to "ConverterController".
  1. Select the "ConverterController" class in the browser, then activate the Inspector window and choose "Attributes" from the popup menu at the top of the Inspector. At the bottom of the "Attributes" view is a list of actions or outlets. Select "Outlets", and use the "Add" button to add four fields:

Start Previous

Attachments