这就是我在 viewDidLoad 方法中访问 plist 中字典的方式:
NSString* documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"Level.plist"];
filePath = [documentsDir stringByAppendingPathComponent:fileName];
array = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
dict = [array objectAtIndex:1];
这很好用,然后我这样写字典:
score = [NSString stringWithFormat:@"%d", score.integerValue + 10];
[dict setObject:score forKey:@"Score"];
[dict writeToFile:filePath atomically: NO];
这也可以正常工作,但是一旦我返回此视图并尝试在 viewDidLoad 方法中再次访问字典,它就会为字典返回 (null)。