Settings Radio Group Element

Whilst playing with the iCloud key-value store I came across a new element for the iOS settings application. The Radio Group element was introduced in iOS 5 and is similar in functionality to the Multi Value element. Most of the iOS documentation does not yet mention the Radio Group element with the exception of the Settings Application Schema Reference. Also Xcode 4.2 does not provide direct support when editing the settings property list which makes it a pain to add.

Both elements allow the user to choose one option from a list of possible options but the Radio Group element avoids the need to display the choices on a second page. To illustrate the difference I will add both Multi Value and Radio Group elements to the settings bundle I used to illustrate how to add a settings bundle to an iPhone app. Refer back to that earlier post for the basics on setting up user preferences.

Multi Value Element

The visual appearance of the Multi Value element is shown below for the Retry preference:

The preference is displayed as a singe line which when tapped takes the user to a second page where the available options can be selected:

The equivalent entry in the settings property list is as follows:

The required fields are as follows:

You can also add a ShortTitles array which provides a shorter string to show in the preference row. Notice in the previous screenshots how the first page show the current value as “Always” whereas the corresponding value on the second page has the longer title “Always Retry”.

Radio Group Element

The Radio Group element removes the need to have a second page and shows all of the options on the initial preferences page as shown below for the Sync preference:

The entry in the settings property list is as follows:

At the time I am writing this post I am using Xcode 4.2 which does not show the Radio Group as a valid option in an iPhone settings list. This has the side effect that the Item line incorrectly shows the values from the previous item in the settings list. However this does not impact the values written to the settings file (right-click on the file and use Open As > Source Code to see the actual XML).

The fields are similar to the Multi Value element except that the title is now optional since it serves as the title of the table section. Also you can add a FooterText string to include some extra explanatory text below the table group.

Setting and Accessing Values

Both preference settings can be accessed in a similar way via the NSUserDefaults class:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger syncType = [defaults integerForKey:@"syncType"];
NSInteger retry = [defaults integerForKey:@"retryStrategy"];

Wrapping Up

As long as you do not have a huge list of settings I think the Radio Group element is a nicer choice for selecting from a set of options. It avoids the extra page and the title and footnote help make the settings easier to understand. I guess I should file some bug reports on Xcode and the documentation to ask Apple to update them now that the dust is settling from all the recent launch activity.

Never miss a post!

iOS Size Classes Cheat Sheet

Subscribe and get my free iOS Size Classes Cheat Sheet

Success! Now check your email to confirm your subscription and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time.
No time to watch WWDC videos?

Sign up to get my iOS posts direct to your inbox and I will send you a free PDF of my iOS Size Classes Cheat Sheet.

OK! Check your inbox (or spam folder) for an email to confirm your details and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time.
Archives Categories