Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning iOS5 Development.pdf
Скачиваний:
7
Добавлен:
09.05.2015
Размер:
15.6 Mб
Скачать

138

CHAPTER 6: Multiview Applications

Figure 6–5. Mobile Safari features a toolbar at the bottom. The toolbar is like a free-form bar that allows you to include a variety of controls.

Each of these multiview application types uses a specific controller class from the UIKit. Tab bar interfaces are implemented using the class UITabBarController, and navigation interfaces are implemented using UINavigationController.

The Architecture of a Multiview Application

The application we’re going to build in this chapter, View Switcher, is fairly simple in appearance, but in terms of the code we’re going to write, it’s by far the most complex application we’ve yet tackled. View Switcher will consist of three different controllers, three nibs, and an application delegate.

When first launched, View Switcher will look like Figure 6–6, with a toolbar at the bottom containing a single button. The rest of the view will contain a blue background and a button yearning to be pressed.

www.it-ebooks.info

CHAPTER 6: Multiview Applications

139

Figure 6–6. When you first launch the View Switcher application, you’ll see a blue view with a button and a toolbar with its own button.

When the Switch Views button is pressed, the background will turn yellow, and the button’s title will change (see Figure 6–7).

www.it-ebooks.info

140

CHAPTER 6: Multiview Applications

Figure 6–7. When you press the Switch Views button, the blue view flips over to reveal the yellow view.

If either the Press Me or Press Me, Too button is pressed, an alert will pop up indicating which view’s button was pressed (see Figure 6–8).

www.it-ebooks.info

CHAPTER 6: Multiview Applications

141

Figure 6–8. When the Press Me or Press Me, Too button is pressed, an alert is displayed.

Although we could achieve this same functionality by writing a single-view application, we’re taking this more complex approach to demonstrate the mechanics of a multiview application. There are actually three view controllers interacting in this simple application: one that controls the blue view, one that controls the yellow view, and a third special controller that swaps the other two in and out when the Switch Views button is pressed.

Before we start building our application, let’s talk about the way iPhone multiview applications are put together. Most multiview applications use the same basic pattern.

The Root Controller

The nib file is a key player here. For our View Switcher application, you’ll find the file MainWindow.xib in your project window’s Resources folder. That file contains the application delegate and the application’s main window, along with the File’s Owner and First Responder icons. We’ll add an instance of a controller class that is responsible for managing which other view is currently being shown to the user. We call this controller the root controller (as in “the root of the tree” or “the root of all evil”) because it is the first controller the user sees and the controller that is loaded when the application loads.

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]