3.1. Basic User Interface Elements

This chapter is designed to get you comfortable building with the basic user interface components of UI Kit. The more advanced components will be covered in Chapter 10. The basic components include the following:



Windows, views, and view controllers

Windows and views are the most basic classes for creating any type of user interface. A window represents a geometric space on a screen, while a view class fills that void with its own functionality. Smaller UI components, such as navigation bars, buttons, and text boxes are all attached to view classes, and a view is anchored to a window.

A view controller is a type of controller class that encapsulates and controls a view. The controller manages the view and how it's rendered on the screen. This augments the view with additional functionality such as built-in support for screen rotations, transitions, and other screen events.



Text views

Text views are specialized view classes for presenting editor windows to view or edit text. The Notepad application is a good example of a simple text view. They are considered humble and are rarely used in light of UI Kit's repertoire of more spectacular classes, but are a great start to get you accustomed to UI Kit.



Navigation bars and controllers

The iPhone UI treats different screens as if they are "pages" in a book. Navigation bars are frequently used to provide a visual prompt to allow the user to return "back" to a previous view, supply buttons to modify elements on the current screen page, and display a number of controls such as segmented controls and toolbars. Navigation bars are found in nearly all preloaded iPhone applications.

A navigation controller can manage the navigation for multiple view controllers in such a way that view controllers can be pushed and popped from a view stack, leaving all the work of changing the navigation bar to the controller. Each view controller hosts its own set of navigation bar properties that are displayed by the navigation controller when the view becomes active.



Transitions

Consistent with the spirit of Apple's user-friendly interfaces, window transitions were introduced with the iPhone to allow the user to perceive navigation through the application's screens like pages in a book. Animations are used to make this visual transition from one view to another, rather than simply flashing to the next screen.



Alert views and action sheets

The iPhone equivalents to pop-up alert windows are alert views and action sheets. These appear as modal windows that can pop or slide to the forefront of the screen when an operation requires the user's attention. These are frequently seen on preloaded iPhone applications when a user receives an alert (such as a text message), or attempts to delete certain items (such as voicemail). You can program action sheets to ask the user any question and present a number of different buttons for the response. They prove useful in parts of an application needing immediate attention.



Table views and controllers

Table views are lists that you can use to display files, messages, or other types of collections. They are used for the selection of one or more items in a list-like fashion. The table objects are very flexible and allow the developer to define how a table cell should look and behave. You can tailor tables to display simple lists, grouped preferences, and rolodex-like section lists. This chapter will cover simple tables, and you'll learn about the more advanced uses for tables in Chapter 10.

A table view controller manages a table view object and can incorporate the added support of a view controller to a table view. Table view controllers provide automatic handling of screen rotations and other events, and you can push the view controller onto a navigation stack for easy navigation, just like other view controllers. Table view controllers can also act as the data source for propagating a table with information to display.



Status bar manipulation

The status bar is the small bar appearing at the top of the iPhone screen, and displays the time, battery life, and signal strength. You can customize the status bar's style, opacity, and other properties.



Application badges

Applications needing to notify the user of time-sensitive information have the ability to display badges on the iPhone's home screen (the springboard). This alerts the user that your application needs attention and unread messages or other new information is waiting to be viewed. These are used heavily by applications using EDGE or 3G networks to deliver messages.



Application services

When an application resigns its active status, resumes, or is terminated, different methods are notified for an application to handle immediate cleanup or save state. These are sent to the application's delegate, which can then respond by cleaning up or saving important information.