Đang chuẩn bị liên kết để tải về tài liệu:
beginning iphone 3 development exploring the iphone sdk phần 7

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Nếu bạn đã thực hiện chương trình ca cao trên Mac, bạn có thể đã quen thuộc với NSUserDefaults, bởi vì nó là lớp được sử dụng để lưu trữ và đọc các ưu đãi trên Mac. Ứng dụng của bạn sẽ sử dụng NSUserDefaults để đọc và lưu trữ dữ liệu ưu đãi bằng cách sử dụng một giá trị quan trọng, | 322 CHAPTER 10 Application Settings and User Defaults Figure 10-1. The Settings application icon is the third one down in the last column. It may be in a different spot on your iPhone or iPod touch but it s always available. Figure 10-2. The Settings application The Settings application acts as a common user interface for the iPhone s User Defaults mechanism. User Defaults is the part of Application Preferences that stores and retrieves preferences. User Defaults is implemented by the NSUserDefaults class. If you ve done Cocoa programming on the Mac you re probably already familiar with NSUserDefaults because it is the same class that is used to store and read preferences on the Mac. Your applications will use NSUserDefaults to read and store preference data using a key value just as you would access keyed data from an NSDictionary. The difference is that NSUserDefaults data is persisted to the file system rather than stored in an object instance in memory. In this chapter we re going to create an application add and configure a settings bundle and then access and edit those preferences from within our application. One nice thing about the Settings application is that you don t have to design a user interface for your preferences. You create a property list defining your application s available settings and the Settings application creates the interface for you. There are limits to what you can do with the Settings application however. Any preference that the user might need to change while your application is running should not be limited to the Settings application because your user would be forced to quit your application to change those values. Download at Boykma.Com CHAPTER 10 Application Settings and User Defaults 323 Immersive applications such as games generally should provide their own preferences view so that the user doesn t have to quit in order to make a change. Even utility and productivity applications might at times have preferences that a user .