我正在尝试使用 NSUserDefaults 将 2 个字符串保存到一个数组中,但是当我想获取这些字符串时会出现一些问题。
这是我的代码:
- (IBAction)closeSettingsView:(id)sender {
NSArray *saveStrings = [[NSArray alloc] initWithObjects:@"%@", @"%@", yourNameTextField.text, customPhraseTextField.text, nil];
NSUserDefaults *defaultsFields = [NSUserDefaults standardUserDefaults];
[defaultsFields setObject:saveStrings forKey:@"savedStrings"];
[defaultsFields synchronize];
}
- (void)viewDidLoad {
NSUserDefaults *defaultsFields = [NSUserDefaults standardUserDefaults];
NSArray *loadStrings = [defaultsFields stringArrayForKey:@"savedStrings"];
NSString *nameString = [NSString stringWithFormat:@"%@", [loadStrings objectAtIndex:0]];
NSString *phraseString = [NSString stringWithFormat:@"%@", [loadStrings objectAtIndex:1]];
NSLog(@"%@", nameString);
NSLog(@"%@", phraseString);
}
这是我的日志:
2013-07-09 02:59:31.639 Alarm Pro[219:60b] %@
2013-07-09 02:59:31.642 Alarm Pro[219:60b] %@
我该怎么做才能正确读取字符串?