应用程序关闭时如何保存值
我是 iPhone 编程新手..
我的应用程序就像一个测验..它有不同类型的测验,每种测验类型都有很多问题 我想在应用程序关闭时保存字符串(测验名称)和整数(问题编号)等值 因此,当应用程序重新启动时,我想通过使用保存的值继续停止的位置
如何执行此操作...?
任何人都可以帮我做到这一点吗...
谢谢你
i am new to iPhone programming..
my app is just like a quiz.. it has different type of quizs and many question in each quiz type
i want to save the values like strings(quiz name) and integers(question number) when an application is closed
so when the app is restarted i want to continue where it was stopped by using saved values
How to do this...?
Can any body help me to do this please....
Thank u
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
保存字符串:
加载字符串:
阅读更多信息:
To save a string:
To load a string:
Read more at: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html
我建议您查看核心数据并在输入时保存答案。然后当应用程序重新启动时,你需要找到一种方法来快速加载相关数据(实际上,你会发现你不需要加载那么多,这也可以帮助你减少需要保存的数据。)
记住,简单这是本质,延迟加载非常有帮助。在需要之前不要加载任何不需要的东西。
Apple 的一个很好的例子是他们随 iPhoneOS 2.0 提供的 SQLiteBooks 示例(我不知道他们是否仍然提供)。
I would suggest you look at Core data and save answers as they are entered. Then when the app is restarted you need to find a way to quickly load the relevant data (Actually, you will find you don't need to load that much, which could also help you reduce what you need to save.)
Remember, simplicity is of the essence, and lazy loading very helpful. Don't load anything you don't need until you need it.
A good Apple example was the SQLiteBooks sample which they provided with iPhoneOS 2.0 (I don't know if they still provide it).
NSUserDefaults 是有利于保存状态和首选项。
NSUserDefaults is good for saving state and preferences.