我有被存储在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