Information Technology Reference
In-Depth Information
There's no doubt that the terminology could be simpler and clearer, especially for newcomers. It becomes easier to
understand when you look at the classes used in Cocoa and Cocoa Touch. UIView and NSView are generic con-
tainers for on-screen content. Controls are usually subclasses of these top-level elements. The class relationships
are easier to understand from the code level than from the top-down design level.
Apple is somewhat evangelical about a design pattern known as Model View Controller (MVC). This aims to split
on-screen content from underlying data models, bridging the gap with controller objects that can abstract the un-
derlying data from the UI. Done properly MVC can create applications that are efficient and easy to maintain, be-
cause the UI only needs to load and display a small subset of the underlying data, without having to make a separ-
ate working copy.
But confusion can occur because some classes that work as controllers also implement a complete view. For ex-
ample, iOS has a class called UIImagePickerController , which not only accesses an iPhone's photo library
and controls the camera, but it also displays its own complete UIs for both. Technically this still its the pat-
tern—the controller abstracts the data and manages the UI—but it blurs developer expectations about what a con-
troller class is likely to do.
It's best not to get hung up on these apparent inconsistencies. MVC is an influence, not a religion, and as long as
you understand how to use the classes and what a view is in approximate terms, you have all the information you
need to work with views successfully.
In iOS, navigation is managed by view switching . Typically, a top-level window object is associated with a naviga-
tion or view controller. When the user requests a new page, the controller loads the next view and displays it. Usu-
ally, it also deletes the previous view after it's no longer visible, to save memory—a process known as lazy loading.
Practical UI design is a combination of object and control layout and view switching code. Usually, you create
subclasses of views and view controllers to run your own UI-specific code, and you design the view layout in In-
terface Builder (IB). But you also can add and remove objects from a view under code control, and some deve-
lopers prefer not to use IB at all.
OS X design is simpler, because views are more static. They may change as the user works with them, but view
swapping is an optional refinement and not a key navigation feature.
TIP
For a guide to developing AppleScript applications, see the companion AppleScript in Wiley's Developer Reference
series.
FIGURE 3.10
The Cocoa-AppleScript template creates a very simple AppleScript application, which launches and…does noth-
ing.
Search WWH ::




Custom Search