我的视图中有3个UIPicker,我想保存应用程序关闭时的选定值。我目前正在使用NSUserDefaults进行其他操作。但是我不确定用于保存选定的UIPickers值的语法。谢谢我的编码员!
最佳答案
这是如何从UIPickerView获取选定的值-
[yourPickerDataArray objectAtIndex:[pickerView selectedRowInComponent:0]];
这是如何在NSUserDefaults中保存值-
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// saving an NSString
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];
// saving an NSInteger
[prefs setInteger:42 forKey:@"integerKey"];
// saving a Double
[prefs setDouble:3.1415 forKey:@"doubleKey"];
// saving a Float
[prefs setFloat:1.2345678 forKey:@"floatKey"];
// This is suggested to synch prefs, but is not needed (I didn't put it in my tut)
[prefs synchronize];
这是如何从NSUserDefaults中检索值-
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"];
关于iphone - 保存在UIPicker中选择的值的最佳方法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8867397/