Reputation: 1442
read in did load:
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];
Write on button click:
- (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"];
}
the plist file:
The error:
2012-09-04 17:03:40.360 app[4849:c07] -[__NSCFString stringValue]: unrecognized selector sent to instance 0x6aa38f0 2012-09-04 17:03:40.362 app[4849:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]: unrecognized selector sent to instance 0x6aa38f0'
Any ideas? cheers.
Upvotes: 0
Views: 285
Reputation:
The dictionary stores NSString objects directly - there's no need to call a (nonexistent) method called - stringValue
. Simply write
nameField.text = [savedData objectForKey:@"name"];
and so on.
(Why do you think this method call would have been necessary?)
Upvotes: 4