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

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

问题描述

请在盲目投票前将这些评论视为重复,然后再查看评论。这不是重复的问题。

首先 - 我使用 MagicalRecord
第二 - 我的 UICollectionView 填充了 NSFetchedResultsController

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

NSFetchedResultsController NSPredicate 是...

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

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

当我使用Magical Record的 saveWithBlock collectionView 正确更新并将更改动画化到视图中。

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

问题是,值被删除到@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 ,因为更改已删除的值应从抓取请求中删除。

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,因为它与 NSManagedObject的 isDeleted 方法冲突

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

请参阅核心数据在父子上下文中的NSPredicate predicateWithBlock和predicateWithFormat
NSPredicate不会在第一次启动时执行
用于不同的示例,如果某个属性被称为已删除,则会发生奇怪的事情。

See Core Data NSPredicate predicateWithBlock and predicateWithFormat in Parent Child Context 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天全站免登陆