通过tableview单元格删除NSUserDefault的对象
我有一个存储在NSUserDefaults中的collections夹列表,单个collections夹由NSDictionary存储:
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];
一切正常,但现在我想用单元格的滑动来删除单个最爱。 我添加了显示删除刷卡的方法,但我不知道如何从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]; }
NSUserDefaults *userPref = [NSUserDefaults standardUserDefaults]; NSMutableDictionary *storedBookMark = [[userPref ObjectForKey:@"bookmarks"]mutable copy]; // If you want to remove an object from the dictionary [storedBookMark removeObjectForKey:@"Your KEy"]; // if you want to empty the dictionary [storedBookMark removeAllObjects]; [userPref setObject: storedBookMark forKey:@"bookmarks"]; [userPref synchronize]; // if you want to store nil // go back to default state .. [userPref setNilValueForKey:@"bookmarks];
- 在球体表面SceneKit上写文字?
- 把一个栏放在UIPageViewController的底部
- 在iOS上使用dev dev编程器可以使用Swift吗?
- 使用AVFoundation在iOS上播放套接字stream的h.264电影
- UITableview Cellexception – '必须将自动resize的掩码转换为约束才能拥有_setHostsLayoutEngine:YES
- MPMoviePlayerViewController,删除quicktime符号/添加背景图像?
- 我的移动开发之旅5
- AVAssetReader和AudioFileReadPackets如何读取audio之间的区别
- 如何做布局来处理IOS 8中的自定义呈现视图控制器的通话(双高度)状态栏?