如何从筛选的UITableView中删除项目,而不实际删除它? [英] How do i delete an item from a Filtered UITableView, without actually deleting it?

查看:48
本文介绍了如何从筛选的UITableView中删除项目,而不实际删除它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,它从FetchedResultsController获取一组Core Data对象.我希望能够使用标准的删除"按钮从表格视图中删除对象,并使表格视图单元格像删除项目时通常那样淡出,但是对于我而言,我不是实际上删除对象,但将其标记为已删除.例如,我有一个名为Deleted的属性,因此它仍然存在,但看起来已删除;

I have a UITableView which gets an array of Core Data objects from a FetchedResultsController. I want to be able to delete an object from the table view using the standard delete button and have the tableview cell fade out like it usually does when an item is deleted, however in my case i am not actually deleting the object but marking it as deleted. Eg/ I have an attribute called deleted, so it still exists but appears deleted;

obj.deleted = [NSNumber numberWithBool:YES];

是否有这种方法可以使它按照标准删除仍然可以正常工作?

Is there such a way to do this so it still appears to work as per a standard delete?

我似乎无法不调用 [self.tableView reloadData] 来执行此操作,因此我失去了标准删除操作所附带的精美动画.

I cant seem to do this without calling [self.tableView reloadData] so i am loosing the nice animations that come with the standard delete.

我的tableView提取结果控制器具有一个过滤器,因此tableView中的数据被过滤了;

My tableView fetched results controller has a filter so the data in the tableView is filtered;

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"deleted == %@", [NSNumber numberWithBool:NO];

怀疑我需要的代码会在这里;

is suspect the code i need would go here;

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //
    }
}

推荐答案

NSManagedObject 已经具有方法 isDeleted ,因此自定义属性 deleted 可能会干扰该方法.您可以向实体添加 invisible 属性并检查

NSManagedObject already has a method isDeleted, so a custom attribute deleted probably interferes with that method. You could add an attribute invisible to your entity and check for

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"invisible == %@", [NSNumber numberWithBool:NO];

在获取的结果控制器中

.如果您设置

in the fetched results controller. If you set

obj.invisible = [NSNumber numberWithBool:YES];

应从表视图中删除该对象.(您可能需要保存上下文,我现在不确定100%.)

the object should be removed from the table view. (You might have to save the context, I am not 100% sure right now.)

这篇关于如何从筛选的UITableView中删除项目,而不实际删除它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆