Define the Classes of Currency Converter
In this section you’ll define controller and model classes for Currency Converter.
Create the ConverterController Subclass
You’ll recall from Chapter 6 that you must go to the Classes display of the nib file window to define a class. Let’s start with the ConverterController class:
In Interface Builder, select the Classes display of the
MainMenu.nib
window.Create an NSObject subclass called ConverterController.
Define Outlets for ConverterController
ConvertorController needs access to the text fields of the interface, so you must create outlets for them. ConverterController must also communicate with the Converter class (yet to be defined) and thus requires a fourth outlet for that purpose.
Select ConverterController in the Classes window.
Click the electrical outlet icon to the right of the class.
Choose Add Outlet from the Classes menu.
Name this outlet
rateField
and press Return.Since the
rateField
outlet is still selected, all you have to do to create more outlets is press Return. Do this once to create thedollarField
outlet, and again for thetotalField
outlet.Add an outlet named
converter
to ConverterController.
Define Actions for ConverterController
ConverterController has one action method,
convert:
. When the user clicks the Convert
button, a convert:
message is sent to the target object, an instance of ConverterController. Action refers both to a message sent to an object when the user clicks a button or manipulates some other ...
Get Learning Cocoa now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.