此代码适用于模拟器,但不适用于设备。我很肯定这与写入文件有关:
NSString *path = [[NSBundle mainBundle] pathForResource:@"SongData" ofType:@"plist"];
NSArray *tempData = [[NSArray alloc] initWithContentsOfFile: path];
NSMutableArray *arr = [[NSMutableArray alloc] init];
for (NSDictionary *dict in tempData) {
NSMutableDictionary *new = [[dict mutableCopy] autorelease];
if ([[new objectForKey:@"Song Title"] isEqualToString:[[tableData objectAtIndex:[indexPath row]] objectForKey:@"Song Title"]]) {
BOOL fav = [[new objectForKey:@"Favorite"] boolValue];
[new setObject:[NSNumber numberWithBool:!fav] forKey:@"Favorite"];
}
[arr addObject:new];
}
[arr writeToFile:path atomically:YES];
我基本上是在写文件 NSMutableArray,我不确定原子意味着什么,但我尝试了是和否,两者都不起作用。
谢谢。