NSFetchedResultsController 更新类型错误 [英] NSFetchedResultsController updating with wrong update type

查看:17
本文介绍了NSFetchedResultsController 更新类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在盲目投票为重复之前查看评论.这不是重复的问题.

首先 - 我将 MagicalRecord 用于核心数据.第二 - 我的 UICollectionView 填充了 NSFetchedResultsController.

First - I'm using MagicalRecord for core data. Second - My UICollectionView is populated with an NSFetchedResultsController.

NSFetchedResultsControllerNSPredicate 是 ...

NSPredicate *eventPredicate = [NSPredicate predicateWithFormat:@"event = %@", self.event];
NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deleted == NO"];

NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[eventPredicate, deletedPredicate]];

当我使用 Magical Record 的 saveWithBlock 向 CoreData 添加新项目时,collectionView 会正确更新并将更改动画化到视图中.

When I add new items to CoreData using Magical Record's saveWithBlock the collectionView updates properly and animates the changes into view.

问题是当我把deleted的值改成@YES...

The problem is that when I change the value of deleted to @YES...

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
    Photo *photo = [[self photoAtIndexPath:[self.collectionView indexPathForCell:cell]] inContext:localContext];
    photo.deleted = @YES;
}];

然后 NSFetchedResultsController 委托方法触发,除非它使用更改类型 NSFetchedResultsChangeUpdate 触发.但这不是它应该的样子.它应该是 NSFetchedResultsChangeDelete 因为更改 deleted 的值应该将其从获取请求中删除.

Then the NSFetchedResultsController delegate methods fire except it fires with the change type NSFetchedResultsChangeUpdate. This isn't what it should be though. It should be NSFetchedResultsChangeDelete as changing the value of deleted should remove it from the fetch request.

我不想只删除对象,因为我需要使用已删除的 ID 更新服务器.

I don't want to just delete the object as I need to update a server with the deleted ID.

此外,如果我随后弹出视图并再次将其推回,则照片消失了,因此我知道它正在正确更新它,并且我知道它正在从获取请求中删除它.

Also, if I then pop the view and push it back again the photo is gone so I know it is updating it properly and I know it's removing it from the fetch request.

有什么想法吗?

推荐答案

你不能调用属性deleted",因为这与 NSManagedObjectisDeleted 方法冲突.

You must not call an attribute "deleted", because that conflicts with the isDeleted method of NSManagedObject.

请参阅 核心数据 NSPredicate "deleted == NO"没有按预期工作NSPredicate 在首次启动时未执行如果属性被称为已删除",则会发生奇怪的事情"的不同示例.

See Core Data NSPredicate "deleted == NO" does not work as expected or NSPredicate does not get executed on first launch for different examples that "strange things" happen if an attribute is called "deleted".

这篇关于NSFetchedResultsController 更新类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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