loading data into UITextField isn't working
no idea why, but this simply isn't working. it's supposed to load some values from a plist file, and load them into some UITextFields. it does output with the NSLogs everything you would expect, but but the text on the UITextFields aren't the same. it almost seems as if its randomly choosing where to put what.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSMutableString stringWithFormat:@"%@.plist",file]];
NSDictionary *loadDict;
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
NSLog(@"hey its there!");
loadDict = [[NSDictionary alloc] initWithContentsOfFile:filePath]开发者_如何学编程;
[numSidesBox setText:[loadDict valueForKey:@"numSides"]];
NSLog([loadDict valueForKey:@"numSides"]);
[numSidesBox setText:[loadDict valueForKey:@"numDice"]];
NSLog([loadDict valueForKey:@"numDice"]);
[numSidesBox setText:[loadDict valueForKey:@"modifier"]];
NSLog([loadDict valueForKey:@"modifier"]);
[numSidesBox setText:[loadDict valueForKey:@"numRolls"]];
NSLog([loadDict valueForKey:@"numRolls"]);
}
else{
NSLog(@"hey its not =(");
}
It appears that you are setting the text of the same text box again and again. So, numSidesBox
should always contain the text of [loadDict valueForKey:@"numRolls"]
. I assume that you have more than one text field, so just change numSidesBox
to the other variables like numDiceBox
or whatever you call them.
P.S. I would also suggest using objectForKey:
rather than valueForKey:
.
You said "TextFields" plural, but you are only using one UITextField(?).
[numSidesBox setText:[loadDict valueForKey:@"numSides"]];
NSLog([loadDict valueForKey:@"numSides"]);
[numSidesBox setText:[loadDict valueForKey:@"numDice"]];
NSLog([loadDict valueForKey:@"numDice"]);
[numSidesBox setText:[loadDict valueForKey:@"modifier"]];
NSLog([loadDict valueForKey:@"modifier"]);
[numSidesBox setText:[loadDict valueForKey:@"numRolls"]];
NSLog([loadDict valueForKey:@"numRolls"]);
Only numSidesBox? Is it correct?
精彩评论