iPhone Xcode Settings.bundle Plist
我按照教程进行操作: http://useyourloaf.com/blog/2010/5/18/adding-a-settings-bundle-to-an-iphone-app.html
和切换开关(我刚刚根据教程)不在设置应用程序中。每次我对开关状态执行 NSLog 时,它都会返回“(null)”。
请帮助我,因为我需要创建并访问在 .plist 文件中创建的切换开关。我是 iPhone 编程新手。
这是我用来设置用户首选项开关的代码:
// Set the application defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"YES" forKey:@"ShuffleToggleKey"];
[defaults registerDefaults:appDefaults];
[defaults synchronize];
这是我用来获取用户首选项开关状态的代码:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL enabled = [defaults boolForKey:@"ShuffleToggleKey"];
我的设置包 Root.plist 文件如下所示:
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:@"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"];
My Settings bundle Root.plist file looks as follows:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保按照教程所述,告诉应用程序您正在为 iPhone 设置创建 plist:
要设置应用程序默认值,您可以考虑尝试以下代码:
这将初始化用户手机上的默认数据库,并为您处理首选项存储。
Make sure that, as the tutorial says, you tell the app that you're creating a plist for iPhone settings:
To set the application defaults, you might consider trying this code instead:
This will initialize a default database on the user's phone, and take care of preference storage for you.