iPhone NSUserDefaults

时间:2011-03-09 08:01:52

标签: iphone nsuserdefaults

我在NSUserDefaults中存储了NSString值,但是不知道如何将该存储的值检索到另一个字符串中。

4 个答案:

答案 0 :(得分:3)

Kashif查看 this 教程并查看数据检索部分....就像这样

Retrieving

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// getting an NSString
NSString *myString = [prefs stringForKey:@"keyToLookupString"];

// getting an NSInteger
NSInteger myInt = [prefs integerForKey:@"integerKey"];

// getting an Float
float myFloat = [prefs floatForKey:@"floatKey"];

答案 1 :(得分:0)

使用它来访问

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

        yourString= [standardUserDefaults objectForKey:@"key"];

答案 2 :(得分:0)

设定值

NSString* pin = @"somthig";
[[NSUserDefaults standardUserDefaults] setObject:pin forKey:@"TokenPin"];

获得价值

NSString* pin;
pin = (NSString*)[[NSUserDefaults standardUserDefaults] objectForKey:@"TokenPin"];

答案 3 :(得分:0)

您可以像下面一样使用

NSString *retrieveString =[[NSUserDefaults standardUserDefaults] objectForKey: @"key"];