我必須在我的plist文件中修改存儲在bundle中的BOOL值。我能夠訪問我必須修改的字典。從nslogging中我可以看到該字典用新的值,但問題是,當我檢查的plist捆綁是不是被modified.any線索,它爲什麼不更新的plist修改一個plist不起作用
NSString* plistPath = nil;
NSFileManager* manager = [NSFileManager defaultManager];
if (plistPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"TopicsList.plist"])
{
if ([manager isWritableFileAtPath:plistPath])
{
NSMutableArray* dictarrays = [NSMutableArray arrayWithContentsOfFile:plistPath];
NSMutableDictionary *dict=[dictarrays objectAtIndex:indexPath.row];
NSLog(@"%@ ",dict);
[dict setObject:[NSNumber numberWithBool:YES] forKey:@"isPaid"];
NSLog(@"%@ ",dict);
[dict writeToFile:plistPath atomically:NO];
NSLog(@"%@ ",dict);
[manager setAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] ofItemAtPath:[[NSBundle mainBundle] bundlePath] error:&error];
}
}
和@Nayefc這樣就意味着我應該在Xcode中刪除我的plist的參考和保存的plist在我的項目文件夾? – sujith1406 2011-06-16 08:32:24
保留在那裏。在應用程序啓動時,將plist從您的包中複製到應用程序的Document文件夾(如果它尚不存在)。用相關的代碼更新我的答案(應該在應用程序中去:didFinishLaunchingWithOptions: – lostInTransit 2011-06-16 10:09:56