IPhone SDK: application preferences

Source: Internet
Author: User
"Edit this Knol" button to switch to edit mode and change this
Field. '> subtitle

Knol-content-LTR ">
Mode and change this field. '> an iPhone application can be configured
The settings menu, this tutorial extends strates how you can make
Settings view for your app and then read the selected settings from your
Application.

Contents

  • Step 1: Create a sample application
  • Step 2: Create a settings bundle
  • Step 3: Define settings Schema
  • Psgroupspecifier
  • Pstitlevaluespecifier
  • Key:
  • Defaultvalue:
  • Pstextfieldspecifier
  • Key:
  • Defaultvalue:
  • Issecure
  • Keyboardtype
  • Autocapitalizationtype
  • Autocorrectiontype
  • Pssliderspecifier
  • Key:
  • Minimumvalue
  • Maximumvalue
  • Defaultvalue:
  • Pstoggleswitchspecifier
  • Key:
  • Truevalue:
  • Falsevalue:
  • Defaultvalue:
  • Psmultivaluespecifier
  • Key:
  • Values:
  • Titles:
  • Defaultvalue:
  • Pschildpanespecifier
  • Key:
  • File:
  • Step 4: Retrieving values of settings
  • Step 5: loading a child pane
  • Concluding Note
  • Appendix A: nslogs
Step 1: Create a sample application

 

I have used
Application similar to the one created in the tutorial presented here (iPhone
SDK Hello World
).

Step
2: Create a settings bundle

Create a new file command + N and
Then selectSettings
From the side menu andSettings bundle
.
The file must be named settings. Bundle to work correctly.

This will create two
New files root. Strings and root. plist. Open the root. plist file and you
Shocould see the following screen listing some sample settings. This is
Actually a graphical representation of an XML file which defines
Settings and how they are displayed. (You can see the XML code by right
Clicking the file and selectingOpen as plain text
)

Step
3: Define settings Schema

The root element has three child
Elements (1)Title;
Which defines the title of this settings View
And is set to the name of the application. (2)Stringtable;

Which is not covered in this tutorial. (3)Preferencespecifiers

Which contains all the settings we wish to elicit from the user.
Preferencespecifiers has type array and has a child element of Type
Dictionary for each setting: item 1, item2 and so forth. We can add
Items by selecting preferencespecifiers and clicking the grey button
The end of the row.

Each setting has several properties of Type
String including the Common Required properties; title and type (note
All strings are case sensitive). The title defines the label displayed
Beside the control used to modify the setting and type defines the type
Of Control used. There are seven possible controls which can be selected
Using the type property:

Psgroupspecifier

This is the simplest
Control and has only the two properties defined described above. It is
Used as a separator to break-up groups of similar settings. It cannot
Accept any input from the user.

Pstitlevaluespecifier

This displays a "Read Only" setting it cannot accept input from
User but can be used to display settings changed elsewhere.

Key: This
Is a string property which can be set to any text, the text is used as
Key to map to the value that a user will enter into the control.



Defaultvalue:

Another string
Property which can store any text, this defines the text that will be
Displayed in the specifier.

Pstextfieldspecifier

The
Next type of control is the textfield, it has some additional
Properties which are listed below

Key: This is a string
Property which can be set to any text, the text is used as a key to map
To the value that a user will enter into the text field.


Defaultvalue:

Another
String property which can store any text this defines the initial text
That will be entered into the textfield when it is first loaded.

Issecure

This
Is a boolean property which Defines if the charecters of the text field
Will be hidden, set to enabled for password fields.

Keyboardtype

A
String property which can have one of the following values:Alphabet
,
Numbersandpunctuati
On
,Numberpad
,URL
,Emailaddress
.
This property specifies which type of keyboard to display when text
Field is selected


Autocapitalizationtype

A string
Property which can have one of the following values:None
,Sentences
,
Words
,Allcharacters

Autocorrectiontype

A string property which can have one of the following values:Default
,
No
,Yes



 

Pssliderspecifier

This
Displays a slider on a bar which allows the user to select a number in
Specified range. In addition to the standard title and type specifiers
The slider has the following properties.

Key: This
Is a string property which can be set to any text, the text is used as
Key to map to the value that a user will enter into the control.





Minimumvalue

A property storing a numerical value which
Corresponds to the slider being on the left end of the bar.

Maximumvalue

A property storing a numerical value which corresponds to the slider
Being on the right end of the bar.

Defaultvalue:

A
Numerical property which defines the original position of the slider.

Pstoggleswitchspecifier

Displays
A toggle switch which can be eitherOn
OrOff.

Key: This
Is a string property which can be set to any text, the text is used as
Key to map to the value that a user will enter into the control.

Truevalue:

A boolean property which defines the value of the control of the toggle
Button is in the on position.

Falsevalue:

A
Boolean property which defines the value of the control of the toggle
Button is in the off position.

Defaultvalue:

A boolean
Property which defines the position of the toggle button the first time
It is loaded.

Psmultivaluespecifier
Multi-value specifier

Displays a list in a second view and allows the user to select one
Element from the list.

Key:

This is a string Property
Which can be set to any text, the text is used as a key to map to
Value that a user will enter into the control.

Values:

A
Property of type array which stores sub-elements of Type string, each
Element provides a A pos sible value for the control to take.



Titles:

A
Property of type array which stores sub-elements of Type string, each
Element provides a textual representation of one of the values specified
In the previous property. For example if the first element of
Values array is "01" and the first element of the titles array is
"January" then the user is shown January but if January is selected
Value stored for the control is 01.


Defaultvalue:

Another string property that defines the initial value of the control,
Shocould be one of the elements of the values list.

Pschildpanespecifier

 

Key:

This is a string property which can be set to any text, the text is
Used as a key to map to the value that a user will enter into
Control.

File:

The
Name of another plist file without the extension.

Step 4: Retrieving values
Settings

You can retrieve the value of a setting by using
Command given below; replace the hilighted text with the name of
Setting you want to get the value.

Nsstring * settingvalue =
[[Nsuserdefaults standarduserdefaults] stringforkey: @ "<setting key>
"]

Step 5: loading a child pane

The final of the seven
Controls allows you to add a sub view. The procedure to do so is to add
A new file command + N and selectOther
From the menu on
RightProperty list
From the list of FLE types.

Create
Child prefernces schema exactly as you created the original schema.

No
In the original schema Add a pschildpanespecifier and addFile
Item to the specifier with the file name of the child view (less
Extension ).

Technically this shoshould be enough but as you will see
If you run your code now the child view will not load. to load your
Child view the child plist file has to be inside the settings bundle
I can't find a way of doing this from within xcode (after half an our
Of random tinkering). So just open a terminal and move the file into
Bundle manually. To do this browse to the directory containing your
Xcode project, and find child. plist file (or whatever you named it). Use
MV child. plist settings. Bundle/child. plist to move your file and then
Click build and go in xcode.

If there is some way of moving
Files into the bundle through xcode that you know of please leave
Coment and I will update this document.


Concluding
Note

This document is a bit raw please leave feedback in case
Anything is not clear, you have some suggestions or if you spot any
Mistakes.

You can find the source code of the example at my
Website;
Source
Code

Appendix A: nslogs

To see the nslog
Output generated by clicking the "load Preferences" button in the sample
Code click the highlighted button in shown in the figure. It will open
The log output window.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //

 

Http://knol.google.com/k/usman-ismail/iphone-sdk-application-preferences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.