iPhone Xcode Settings.bundle Plist

发布于 2024-10-06 07:29:02 字数 940 浏览 0 评论 0原文

我按照教程进行操作: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱给你人给你 2024-10-13 07:29:02

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

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

要设置应用程序默认值,您可以考虑尝试以下代码:

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

这将初始化用户手机上的默认数据库,并为您处理首选项存储。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文