开发者

iPhone Xcode Settings.bundle Plist

开发者 https://www.devze.com 2023-01-28 23:58 出处:网络
I followed the tutorial: http://useyourloaf.com/blog/2010/5/18/adding-a-settings-bundle-to-an-iphone-app.html

I followed the tutorial: http://useyourloaf.com/blog/2010/5/18/adding-a-settings-bundle-to-an-iphone-app.html

And the Toggle Switch (that I just created based on the tutorial) was not in the Settings App. Every time I did an NSLog on the state of the switch, it would return "(null)".

Please help as I need to create, and access a Toggle Switch created in the .plist file. I am new to iPhone Programming.

Here's the code I'm using to set the user preference switch:

// Set the application defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"Y开发者_JAVA技巧ES" forKey:@"ShuffleToggleKey"];
[defaults registerDefaults:appDefaults];
[defaults synchronize];

And here's the code I'm using to get the state of the user preference switch:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL enabled = [defaults boolForKey:@"ShuffleToggleKey"];

My Settings bundle Root.plist file looks as follows:

iPhone Xcode Settings.bundle Plist


Make sure that, as the tutorial says, you tell the app that you're creating a plist for iPhone settings:

Select the Root.plist file, click on the Root entry in the detail view to ensure it is selected and then from the Xcode view menu select Property List Type -> iPhone Settings plist.

To set the application defaults, you might consider trying this code instead:

// Set the application defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:YES forKey:@"ShuffleToggleKey"];
[defaults synchronize];

This will initialize a default database on the user's phone, and take care of preference storage for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消