如何保存iPhone应用程序的用户首选项? [英] How do I save user preferences for my iPhone app?

查看:103
本文介绍了如何保存iPhone应用程序的用户首选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题标题几乎让它消失了 - 我希望我的应用程序记住一些事情。它是某种计算器,所以它应该保存最后使用的值和一些用户可选设置。

The question title pretty much gives it away - I'd like my app to remember a few things. It's some sort of calculator, so it should save the last used values and some user selectable settings.

基本上我想保存一些浮点数和BOOL并加载下次应用程序加载时再次出现。

Basically I'd like to save a handful of floats and BOOLs and load them again the next time the app loads.

最好和最简单的方法是什么?

What's the best and easiest way to do that?

谢谢!!

推荐答案

最简单的方法之一是将其保存在 NSUserDefaults的 :在

One of the easiest ways would be saving it in the NSUserDefaults:

设定:

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

[userDefaults setObject:value 
                 forKey:key];
// – setBool:forKey:
// – setFloat:forKey:  
// in your case 
[userDefaults synchronize];

获取:

[[NSUserDefaults standardUserDefaults] objectForKey:key];

– boolForKey:

- floatForKey:在你的情况下。

这篇关于如何保存iPhone应用程序的用户首选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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