iOS版:使用一个NSUserDefaults的布尔 [英] iOS: Use a boolean in NSUserDefaults
问题描述
在该 RootViewController的
我的应用程序的加载,我希望能够检查用户是否登录凭据已保存到 NSUserDefaults的
。
When the rootViewController
of my application is loaded, I want to be able to check whether or not the users login credentials have been saved to NSUserDefaults
.
基本上,当用户加载的申请,他/她没有她的登录凭据保存,一个 modalAlertView
将被推,用户将能够保存他们的凭据正确。这样可以节省那些的UITextField
字符串到相应的 NSUserDefault
对象。但是,它是可能的,当心动做,我可以创建一个 NSUserDefault
对象,它是一个布尔值和值更改为是?
Basically, when the user loads the application and he/she doesn't have her login credentials saved, a modalAlertView
will be pushed and the user will be able to save their credentials appropriately. This saves those UITextField
strings to a respective NSUserDefault
object. However, is it possible, that when this saving is done, I can create an NSUserDefault
object which is a boolean and change the value to a yes?
含义与布尔已被设置为无,当用户保存他们的登录凭据,也改变了布尔到是吗?
Meaning that the boolean is already set to no, and when the user saves their login credentials, it also changes the boolean to a yes?
推荐答案
您可以通过设置布尔值:
You can set your boolean by using:
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"logged_in"];
和使用该code阅读:
and read it by using this code:
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"logged_in"]) {
[self displayLogin];
} else {
[self displayMainScreen];
}
这篇关于iOS版:使用一个NSUserDefaults的布尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!