8.1 application setting Concept
8.2 create a configuration bundle
8.3 set the project type
8.4 read settings
8.1 application setting Concept
Application settings: preferences are used in many iOS and Mac OS software. For example, in iOS, we set WiFi, app providers and wallpapers.
8.2 create a configuration bundle
Create a project
Settings bundle)
The preference of an application is stored in the XML file of a root. List, which is associated with the settings bundle. You can specify the project type in the root. List, including the common field type, block type, switch type, and sub-view type.
Create a configuration bundle
Add the setting bundle File Settings. bundle (default name) under the Resource folder ). Expand the settings. Bundle Folder:
The root. plist icon is the attribute list for setting properties.
The en. lproj folder is used for localized applications.
Root. plist preferencespecifiers Node
8.3 set the project type
The generated configuration bundle File Settings Project
From the above running application, we have created some configuration projects for us without writing any code lines.
Psgroupspecifier
Set the project type to psgroupspecifier to indicate that the project is the beginning of a new group, and each project after it will be part of the group until a project with the type value of psgroupspecifier is reached.
In this example, we also need to set the title to group. When there are multiple groups, the title cannot be repeated.
Pstextfieldspecifier
Setting project type to pstextfieldspecifier indicates that the project is a specific type of preference field. Description of other projects:
Pstoggleswitchspecifier
Setting the project type to pstoggleswitchspecifier indicates that the project is a specific type of use preference switch. Description of other projects:
Pssliderspecifier
Setting project type to pssliderspecifier indicates that the project is a specific use preference slider type. Description of other projects
Add the maximum and minimum values to the slider
Show package contents to access the bundle content. This opens a new window. Copy the icon file to this folder. In this way, you can find the two icon files.
Add the maximum and minimum image file structure
Set the image to the bundle:
Running result
Add sub-settings View
After adding the child view, run the program:
8.4 read settings
Read settings in the Application
We use the nsuserdefaults class to read user settings.
Nsuserdefaults * defaults = [nsuserdefaults standarduserdefaults];
The methods for obtaining nsuserdefaults values include:
Arrayforkey: boolforkey: dataforkey:
Dictionaryforkey: floatforkey: integerforkey:
Objectforkey: stringarrayforkey: stringforkey:
Mainviewcontroller. h
Mainviewcontroller. m
Flipsideviewcontroller. h
Flipsideviewcontroller. m
Run
Note:
1. This tutorial is based on instructor Guan Dongsheng.
2 Based on black apple 10.6.8 and xcode4.2
3. I am a beginner. What are you looking?
4. The tutorial will be updated continuously as I learn
5. I copied the document from the word notes. Sorry for the format.