读入确实加载:
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; //5
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
//load in text fields.
NSMutableDictionary *savedData = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
nameField.text = [[savedData objectForKey:@"name"] stringValue];
locationTextField.text = [[savedData objectForKey:@"location"] stringValue];
sectorTextField.text = [[savedData objectForKey:@"sector"] stringValue];
写在按钮点击:
- (IBAction)writingButton:(id)sender
{
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//[data setObject:[NSNumber numberWithInt:value] forKey:@"value"];
[data setObject:[NSString stringWithString:nameField.text] forKey:@"name"];
[data setObject:[NSString stringWithString:locationTextField.text] forKey:@"location"];
[data setObject:[NSString stringWithString:sectorTextField.text] forKey:@"sector"];
}
plist文件:
错误:
2012-09-04 17:03:40.360 app[4849:c07] -[__NSCFString stringValue]: 无法识别的选择器发送到实例 0x6aa38f0 2012-09-04 17:03:40.362 app[4849:c07] *** 终止应用程序到期未捕获的异常 'NSInvalidArgumentException',原因:'-[__NSCFString stringValue]: unrecognized selector sent to instance 0x6aa38f0'
有任何想法吗?干杯。