Nov 97 - Getting Started
Volume Number: 13
Issue Number: 11
Column Tag: Getting Started
VerySimpleText, Version 2
by Dave Mark , Copyright1997, All Rights Reserved
Three months ago, the August Getting Started column featured a program called
VerySimpleText. We built this first version of VerySimpleText using ProjectBuilder
and InterfaceBuilder. We started off by editing the nib file (the first version of
VerySimpleText wrapped its entire user interface into a single nib file).
We added a Format submenu to the application's default menu, thus adding a series of
powerful font, text, and page manipulation features to VerySimpleText. This was done
by dragging a Format menu from the menu palette in the palette window.
We also added a scrollable text area (implemented by the NSScrollView class) to the
default application window. We did this by dragging a scrollable text view from the
DataViews portion of the palette window. We used the NSScrollView inspector to set the
autosizing for this view so the scrollable text view grew and shrank along with its
containing window. We used InterfaceBuilder's Test Interface feature to test out the
window, making sure it looked and behaved as we wanted it to.
Next, we added an info panel (an about box) to VerySimpleText, along with a menu item
to bring up the info panel. We edited an existing menu item (Info Panel...) to create
our "About VerySimpleText..." item. We used the NSMenuItem inspector to enable the
item (unchecking the disabled checkbox, actually). To create the panel itself, we used
the Windows portion of the palette window and dragged out our new window, changing
the name of the window instance in the nib window and the window's title in the
inspector. We also used the palette window to drag some default text into the new info
panel.
Once the about panel was built, we created an AboutPanelController class which
brought up the about panel when the "About VerySimpleText..." item was selected.
Working in the Classes tab within the nib window, we first subclassed NSObject, then
created one outlet (abtWindow) and one action (show:). As a reminder, think of an
outlet as a variable or object you want associated with your class. When
InterfaceBuilder generates the source code for this class, outlets are declared in the
header file as type id. An action is a method. In this case, the show: method will bring
up the about panel.
Once we were done with our nib file, we told InterfaceBuilder to generate the source
files for this project and to add them to the project.
Our next step was to link the "About VerySimpleText..." menu item to the
AboutPanelController so when it was selected, the show: method would get called and
the panel would appear. First, we instantiated our newly created
AboutWindowController class. The instance appeared in the nib window's Instances tab.
We then control-dragged from the "About VerySimpleText..." menu item (it's in the
menu itself) to the AboutWindowController instance in the nib window. In the
inspector window, we clicked the connect button to establish this link. Now, when the
"About VerySimpleText..." item is selected, the AboutWindowController's show: method
will be called.
Next, we control-dragged from the AboutWindowController instance to our
AboutWindow instance. When the link appeared, we moved to the inspector window and
clicked on the abtWindow outlet and clicked the Connect button to establish the link.
This links the AboutWindowController's abtWindow variable to the AboutWindow. We
added a line to the show: method to bring up the window:
- (void)show:(id)sender
[abtWindow makeKeyAndOrderFront:self];
}
The Model, View, Controller Paradigm
Before we move on to this month's additions to VerySimpleText, I thought it might be
useful to talk about the Model, View, Controller paradigm, described in Discovering
OpenStep: A Developer Tutorial. The Model, View, Controller paradigm is also known as
MVC. MVC originated with Smalltalk-80. It categorizes objects as either models,