Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Part of your problem is mentioned under the heading <a href="http://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/Preferences/Preferences.html#//apple_ref/doc/uid/TP40007072-CH6-SW24" rel="nofollow">"Specifying Default Values for Preferences"</a>:</p> <blockquote> <p>default preference values from the application’s Settings bundle are not set until the Settings application runs. This means that if the user runs your application before running Settings, the default values specified in your Settings bundle are unavailable.</p> </blockquote> <p>All the stuff in the Settings bundle doesn't get loaded for your app's defaults database until <em>after</em> the user opens the Settings Application. Does this seem stupid to you? Seems stupid to me. The result is that you need to register all those defaults initially yourself. I wrote this while I was trying to figure out what was going on; improvements can definitely be made, but it should get you started:</p> <pre><code>NSURL * settingsURL = [[NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"Settings" withExtension:@"bundle"]] URLForResource:@"Root" withExtension:@"plist"]; NSDictionary * settingsDict = [NSDictionary dictionaryWithContentsOfURL:settingsURL]; NSArray * settingsArr = [settingsDict objectForKey:@"PreferenceSpecifiers"]; NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; for( NSDictionary * setting in settingsArr ){ NSString * key = [setting objectForKey:@"Key"]; if( !key ) continue; // Some objects don't have keys if( ![defaults objectForKey:key] ){ [defaults setObject:[setting objectForKey:@"DefaultValue"] forKey:key]; } } </code></pre> <p>Another problem that you have is that you don't get an array for <code>PSTitleValueSpecifier</code> keys when you do <code>[defaults objectForKey:@"myTitlePreferencesKey"]</code>; you just get one string. A <code>@"DefaultValue"</code> key/value pair is also required to be part of <a href="http://developer.apple.com/library/ios/#documentation/PreferenceSettings/Conceptual/SettingsApplicationSchemaReference/Articles/PSTitleValueSpecifier.html%23//apple_ref/doc/uid/TP40007015-SW1" rel="nofollow">that item's dictionary</a>. Initially you will get that value, which must be a string. If you change the value, you'll get the string from the <code>Titles</code> array which has the same index as that object in the <code>Values</code> array. I'm pretty sure that if you have a <code>Values</code> array, you also have to have a <code>Titles</code> array.</p> <p>For the second part of your question, if you want to change the values of any of the preferences, you simply do</p> <pre><code>[[NSUserDefaults standardUserDefaults] setObject:myValue forKey:@"myKey"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload