我有被存儲在NSUserDefaults的最愛,單收藏存儲通過NSDictionary的列表:通過的tableview細胞刪除NSUserDefault的對象
NSUserDefaults *userPref = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *bookmark = [NSMutableDictionary new];
[bookmark setValue:author.text forKey:@"author"];
[bookmark setValue:book.text forKey:@"book"];
[bookmarks addObject:bookmark];
[userPref setObject:bookmarks forKey:@"bookmarks"];
[userPref synchronize];
一切都OK了,但現在我想刪除一個單一的最愛與細胞的輕掃。我添加了顯示刪除刷卡的方法,但我不知道如何從nsuserdefaults中刪除單個書籤。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
[self.listBookamrks removeObjectAtIndex:row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
看到我在http://stackoverflow.com/questions/9629810/fail-to-addobject-to-nsmutablearray/9629945#comment12242921_9629945 答案它可以幫助你。 – janusbalatbat 2012-03-10 12:56:53