iPhone Xcode Settings.bundle Plist [英] iPhone Xcode Settings.bundle Plist

查看:126
本文介绍了iPhone Xcode Settings.bundle Plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了该教程:并且拨动开关"(我是根据本教程刚创建的)不在设置"应用程序中.每次我在开关状态上执行NSLog时,它将返回(null)".

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)".

在创建和访问.plist文件中创建的Toggle Switch时,请提供帮助.我是iPhone编程新手.

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"];

我的设置"捆绑包Root.plist文件如下所示:

My Settings bundle Root.plist file looks as follows:

推荐答案

请确保如本教程所述,您告诉应用程序正在为iPhone设置创建plist:

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

选择Root.plist文件,单击 详细信息视图中的根"条目 确保选中它,然后从 Xcode视图菜单中选择属性 列表类型->"iPhone设置" plist.

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.

这篇关于iPhone Xcode Settings.bundle Plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆