iOS:如何创建“用户首选项”特征
我有一个基于 UINavigationController 的应用程序;我希望添加一个“设置”页面,用户可以在其中设置一些功能,例如语言和其他一些首选项。 目前,我希望在其中设置字段的 UIViewController 是 RootViewController 下的 2 个级别(即有一个“主视图”>>您单击一个按钮并输入另一个 UIViewController 并在那里形成您应该能够输入设置 UIViewController)。
我不清楚应该如何保存这些数据以及如何在应用程序加载时调用它。
我读了一些关于 NSUserDefaults 和 Singleton 的博客,但我不清楚应该如何使用它们。
我应该在哪里创建稍后维护用户首选项的数据属性?我应该在 AppDelegate 上还是在 MySettingsViewController (我正在创建的 UIViewController)上创建它们?
我应该使用 Singleton 属性吗?如果是,应该在哪里创建它?
当您说“单例”时,您实际上是指创建静态属性吗?
是否有另一种方法可以在两个不直接连接的控制器之间进行通信(我可以将数据从“底部”ViewController 传输到 RootViewController,通过中间的 UIViewController 将其传递,但这看起来很奇怪且无效)?
任何方向/教程将不胜感激!
I have an application that is based on a UINavigationController; I wish to add a "Setting" page where the user will have the ability to set some features like Language and some other preferences.
Currently the UIViewController where I wish to have the Setting fields in is 2 levels under the RootViewController (i.e. there is a "main view" >> you click on a button and enter another UIViewController and form there you should be able to enter the Setting UIViewController).
I'm not clear about how I'm supposed to save this data and how to call it upon application load.
I read some blogs about NSUserDefaults and about Singleton but I'm not clear how should I use them.
Where should I create the data attributs that will later on maintain the user preferences? Should I create them on the AppDelegate or on the MySettingsViewController (the UIViewController that I'm creating)?
Should I use a Singleton attribute, and if so, where should it be created?
When you say "Singleton", do you actually mean creating a Static attribute?
Is there another way to communicate between 2 controllers that are not directly connected one to the other (I can transfer data from the "bottom" ViewController to the RootViewController passing it via the UIViewController in the middle, but it seems weird and ineffective)?
Any direction / tutorial will be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
绝对使用 NSUserDefaults。太棒了,苹果推荐它。
设置设置:
您还可以存储其他内容,例如文本、数字等,而不仅仅是简单的布尔值。
要检查设置:
Definitely use NSUserDefaults. It's great, and Apple recommends it.
To set a setting:
You can also store other things, such as text, numbers, etc. Much more than a simple boolean.
To check the setting:
我会使用 http://inappsettingskit.com/ 而不是自己动手。我几乎在我开发的每个应用程序中都使用过它,并且它可以完美地处理此类场景的应用程序设置。
I'd use http://inappsettingskit.com/ rather than roll my own. I've used it in almost every application I work on and it handles app settings perfectly for just this sort of scenario.