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

410

CHAPTER 12: Application Settings and User Defaults

productivity applications might, at times, have preferences that a user should be able to change without leaving the application. We’ll also show you to how to collect preferences from the user directly in your application, and store those in iOS’s User Defaults.

In addition, with the introduction of background processing in iOS 4, you can actually switch to the Settings application, change a preference, and then switch back to your application. We'll show you how to handle that situation at the end of this chapter.

The AppSettings Application

We’re going to build a simple application in this chapter. First, we’ll implement a settings bundle so that when the user launches the Settings application, there will be an entry for our application, AppSettings (see Figure 12–3).

Figure 12–3. The Settings application showing an entry for our AppSettings application in the simulator

If the user selects our application, Settings will drill down into a view that shows the preferences relevant to our application. As you can see from Figure 12–4, the Settings application uses text fields, secure text fields, switches, and sliders to coax values out of our intrepid user

www.it-ebooks.info

CHAPTER 12: Application Settings and User Defaults

411

Figure 12–4. Our application’s primary settings view

Also notice the two items in the view that have disclosure indicators. The first one, Protocol, takes the user to another table view that displays the options available for that item. From that table view, the user can select a single value (see Figure 12–5).

The More Settings disclosure indicator allows the user to drill down to another set of preferences (see Figure 12–6). This child view can have the same kinds of controls as the main settings view, and can even have its own child views. You may have noticed that the Settings application uses a navigation controller, which it needs because it supports the building of hierarchical preference views.

www.it-ebooks.info

412

CHAPTER 12: Application Settings and User Defaults

Figure 12–5. Selecting a single preference item from a list

Figure 12–6. A child settings view for our application

www.it-ebooks.info

CHAPTER 12: Application Settings and User Defaults

413

When users launch our application, they will be presented with a list of the preferences gathered in the Settings application (see Figure 12–7).

Figure 12–7. Our application’s main view

In order to show how to update preferences from within our application, we also provide a little information button in the lower-right corner. This button takes users to another view where they can change additional preferences directly in our application (see Figure 12–8).

www.it-ebooks.info

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