gpt4 book ai didi

iphone - 通过 tableview 单元格删除 NSUserDefault 对象

转载 作者:行者123 更新时间:2023-11-29 04:45:52 25 4
gpt4 key购买 nike

我有一个存储在 NSUserDefaults 中的收藏夹列表,单个收藏夹由 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];

关于iphone - 通过 tableview 单元格删除 NSUserDefault 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9646403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com