【发布时间】:2011-05-14 23:50:12
【问题描述】:
此代码适用于模拟器,但不适用于设备。我很肯定这与写入文件有关:
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 文件,我不确定原子意味着什么,但我尝试了是和否,两者都不起作用。
谢谢。
【问题讨论】:
标签: objective-c cocoa-touch nsmutablearray writetofile