问题描述
从CoreDataBook示例开始,我以标准方式在 - (NSFetchedResultsController *)fetchedResultsController
中有谓词。
I have predicate inside of - (NSFetchedResultsController *)fetchedResultsController
in a standard way starting from the CoreDataBook example.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"state=%@ && date >= %@ && date < %@", @"1",fromDate,toDate];
[fetchRequest setPredicate:predicate];
这可以很好地编辑项目,但返回NSFetchedResultsChangeDelete不更新。当主视图返回时,它缺少该项目。
This works fine however when editing an item, it returns with NSFetchedResultsChangeDelete not Update. When the main view returns, it is missing the item. If I restart the simulator the delete was not saved and the correct editing result is shown the the predicate working correctly.
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
我可以通过注释掉两条谓词行来确认行为,在编辑后返回完整集,并调用NSFetchedResultsChangeUpdate而不是NSFetchedResultsChangeDelete。
I can confirm the behavior by commenting out the two predicate lines ONLY and then all works as it should correctly returning with the full set after editing and calling NSFetchedResultsChangeUpdate instead of NSFetchedResultsChangeDelete.
我已阅读
谁报告类似的行为,但我没有找到一个解决我的问题的工作。
I have read http://matteocaldari.it/2009/11/multiple-contexts-controllers-delegates-and-coredata-bugwho reports similar behavior but I have not found a work around to my problem.
推荐答案
根原因是由于使用错误类型的NSPredicate格式字符串设置属性的值。
I meet this problem too. The root reason is caused by setting the value of attribute in the NSPredicate format string with a wrong type.
对于此问题,可能是 state
的属性具有Number类型,如 Integer 32
。但是上面的代码向它传递了一个NSString( @1
),只需将其更改为NSNumber( @ 1
),将解决问题。
For this problem may be the attribute of "state
" has a Number type, like "Integer 32
". But the code above passed a NSString to it(@"1"
), just change it to a NSNumber(@1
), will fixed the problem.
Matthew Weiss 最后通过使用获取请求模板解决了问题。我认为在没有类型问题的模板中选中了 state
。只有fromDate和toDate由subs传递。
Matthew Weiss finally fixed the problem by using fetch request template. I think the "state
" is checked in the template which doesn't have the type problem. And only fromDate and toDate are passed by subs.
这篇关于NSPredicate导致更新编辑返回NSFetchedResultsChangeDelete不NSFetchedResultsChangeUpdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!