简体   繁体   English

iPhone Xcode Settings.bundle Plist帮助

[英]iPhone Xcode Settings.bundle Plist Help

I followed the tutorial: http://useyourloaf.com/blog/2010/5/18/adding-a-settings-bundle-to-an-iphone-app.html 我遵循了该教程: http : //useyourloaf.com/blog/2010/5/18/adding-a-settings-bundle-to-an-iphone-app.html

And the "Shuffle Switch" (that I just created based on the tutorial) was not in the Settings App. 而“ Shuffle Switch”(我只是根据教程创建的)不在Settings App中。 Every time I did an NSLog on the state of the switch, it would return "(null)". 每当我在开关状态上执行NSLog时,它将返回“(null)”。 The "Slideshow Switch" (which was created the same way) worked fine. “ Slideshow Switch”(以相同的方式创建)工作正常。

My Settings bundle Root.plist file looks as follows: (copy link and paste into web browser) i.imgur.com/kb8DT.png 我的设置捆绑包Root.plist文件如下所示:(复制链接并粘贴到Web浏览器中)i.imgur.com/kb8DT.png

Please help as I need to create, and access a Toggle Switch created in the .plist file. 请根据需要提供帮助,并访问在.plist文件中创建的Toggle Switch。 I am new to iPhone Programming. 我是iPhone编程新手。

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:@"YES" 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"];

It seems, that you're putting string object and trying to get boolean value. 看来,您正在放置字符串对象并尝试获取布尔值。 You should or get out the string like 你应该或拿出像这样的字符串

NSString *enabledStr = [defaults stringForKey:@"ShuffleToggleKey"];
BOOL enabled = [enabledStr boolValue];

or put a boolean value in the first place like that: 或像这样首先放置一个布尔值:

  [defaults setBool:YES forKey:@"ShuffleToggleKey"];

Then you can retrieve it as 然后您可以将其检索为

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM