Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2030497
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类:

2010-04-21 12:50:45

  1. What Is Application Settings
    It is used to let you add settings of yourown application to Apple application Settings. What you need do is to prepare a settings bundle, then Apple application Settings will create user interfaces for you. Settings bundle is a group of files built into your application that tells the Apple application Settings what preferences your application wishes to collect from user, settings bundle is in the format of property list.
    The root level preferences view must be defined in Root.plist, if you need addition sub views, you must create new property list file (its name can't be Root.plist), and add entry in Root.plist for each sub view.
    Click Settings icon on iPhone and iPod Touch to launch Settings.
  2. Create Settings Bundle File
    1. Click project name on Group & Files pane in XCode
    2. Click menu File > New File...
    3. In the left pane, select Settings under the iPhone OS heading, then select Settings Bundle icon
    4. Click Next, and choose the default name of Settings. bundle by press Return, but if you want to create settings bundle for sub view, you must change the name.
    5. Now, a new item named Settings.bunder is generated on Group & Files pane in XCode, expand it, you will find 2 items, Root.plist, and a folder named en.lproj.
    6. ...
  3. Settings Bundle Format
    1. Root.plist
      Root node, outmost node, it contains must children:
          - Title(String), the title for our application will display on Settings application
          - StringsTable(String), optional.
          - PreferenceSpecifiers (Array), define available setting items, it holds a set of dictionary nodes (preference node), each of them represents a single preference that the user can enter, or a single child view that the user can drill down into. When you add a new sub node under PreferenceSpecifiers node, the default type is String, you must change it to Dictionary.
    2. Property List For Sub View
    3. Preference Node Format
      The performance node contains several sub nodes, the data type of these sub nodes can be Boolean, Date, Data, Number, String, integer......
      1. Common sub nodes
        - Type (String), Sepcify the type of preference node
        - Title (STring), Specify the visible label for the preference node
        - Key (String), Specify the key used to store the value of this preference item and retrive the value later
      2. Start a new group
        - Type -> PSGroupSpecifier
      3. Text Field
        - Type (String) -> PSTextFieldSpecifier
        - AutoCapitalizationType (String) -> None or other value, means whether to autocapitalize what the user types in
        - AutoCorrectionType (String) -> Yes or No, mean whether to autocorrect values entered into this text field.
      4. Secutity Text Field
        The same as Text Field, but need to add addition sub node:
        - IsSecure (Boolean) -> Check the checkbox at the end of this row
      5. Multivalue Field
        Add a disclosure indicator in this row, click it will take ou down to a tab view to ler you select one of several rows.
        - Type (String) -> PSMultiValueSpecifier
        - Values (Array) -> Hold a list of values that actually get stored in the User Defaults, you need to add sub items under this nodes
        - Titles (Array) -> Hold a list of values that user can select from, you need to add the same account of sub items under this nodes as node Values. If user select the first title, the first value is stored.
      6. Toggle Switch
        - Type (String) -> PSToggleSwitchSpecifier
        - TrueValue/FalseValue -> By default, the value of this control can be YES or NO for on/off state. But you can define yourown value to represent on/off state by define sub node TrueValue and FalseValue, the type of these node can be String, Number, Date.
        - DefaultValue -> If you don't define TrueValue and FalseValue, the type of this node must be Boolean; Otherwise, change the type of it to the same as TrueValue/FalseValue, and set value to that defined in node TrueValue/FalseValue,
      7. Slider
        - Type (String) > PSSliderSpecifier
        - DefaultValue (Number) -> Specify default value for the slider
        - MinimumValue (Number) -> Specify the available minimum value for the slider
        - MaximumValue Number) -> Specify the available maximum value for the slider
        - MinimumValueImage (String) -> Specify a file name of image to display on minimum end of slider, this node is optional
        - MaximumValueImage (String) -> Specify a file name of image to display on maximum end of slider, this node is optional
      8. Child Setting View
        Tell Settings application that we want to diaplay a child settings view. This specifier will present a row with disclosure indicator, when typped, wil take the user down to a whole new view full of preferences.
        - Type (String) -> PSChildPaneSpecifier
        - File (String) -> Specify base name of property list file, such as MySubView for MySubView.plist. You need to create a new setting bundle for the sub view.
      9. ...
    4. ...
  4. Read & Change Settings Using NSUserDefaults
    1. Initial
      NSUserDefaults *defaults = [NSUSerDefaults standardUserDefaults];
    2. Read Settings
      - Get Object, like NSString, NSDate, NSData
          [defaults objectForKey:@"xxxxxx"]; //The key is that defined in settings bundle file
      - Get Scalar, like int, float, boolean
          [defaults intForKey:@"xxx"];
          [defaults floatForKey:@"xxx"];
          [defaults booleanForKey:@"xxx"];
          ....
    3. Shcnage Settings
      - Set Object, like NSString, NSDate, NSData
          [defaults setObject:xxxx forKey:@"yyyy"]; //xxxx is value for key
      - Set Scalar, like int, float, boolean
          [defaults setInt:xxx forKey:@"yyyy"];
          [defaults setFloat:xxx forKey:@"yyyy"];
          [defaults setBoolean:xxx forKey:@"yyyy"];
          ....
    4. ...
  5. Advanced
    More details, please refere to Settings Application Schema Reference
  6. ...
  7. ...

Reference:
  1. Beginning iPhone Development: Exploring the iPhone SDK
    Chapter: Application Settings and User Defaults
    Page: P304~327
  2. ...
阅读(1542) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~