嗨, 我有這樣的plist:從陣列(的plist)可可觸摸刪除字典元素
<plist version="1.0">
<dict>
<key>Rows</key>
<array>
<dict>
<key>FavTitle</key>
<string>Book1</string>
<key>Favourited</key>
<string>duh</string>
<key>SaveName</key>
<string>book1.pdf</string>
</dict>
<dict>
<key>FavTitle</key>
<string>Book2</string>
<key>Favourited</key>
<string>duh</string>
<key>SaveName</key>
<string>book2.pdf</string>
</dict>
</array>
</dict>
</plist>
其中填充我的UITableView像這樣:
cell.text = [dictionary objectForKey:@"FavTitle"];
(是啊是啊,多數民衆贊成貶值)和當選擇一個單元格時,我的字典對象被推送到我的詳細視圖(例如設置Title和UIWebView url),如下所示:
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedSaveName = [dictionary objectForKey:@"SaveName"];
dvController.selectedFavTitle = [dictionary objectForKey:@"FavTitle"];
dvController.selectedFavourited = [dictionary objectForKey:@"Favourited"];
[dvController setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
這就是所有罰款和花花公子,我可以添加到該數組,但我如何從當前加載的字典呢?這是行不通的:
NSString *documentsDirectory = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents/"]];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"Favourites.plist"];
NSMutableDictionary *rootDict = [[NSMutableDictionary alloc] initWithContentsOfFile:writablePath];
NSMutableDictionary *thisFav = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"duh", @"Favourited",
selectedSaveName, @"SaveName",
selectedFavTitle, @"FavTitle",
nil];
[[rootDict objectForKey:@"Rows"] removeObject:thisFav];
[rootDict writeToFile:writablePath atomically: YES];
如何刪除包含字符串'Book2'的條目?我發佈的最後一個片段不起作用!多謝你們!
說明:您想從plist中刪除字典嗎?例如。您必須輸入:Book1和Book2,並且您想要刪除Book2。否則,這個問題根本不明確。 – TechZen 2011-03-03 20:09:46
多孔莫利你好!現在編輯它,抱歉缺乏澄清,謝謝指出那個人! – DexCurl 2011-03-03 20:16:44