我怎么知道设置FetchBatchSize是否有效?

时间:2012-03-09 17:55:10

标签: iphone objective-c core-data

我正在使用NSFetchedResultsController执行NSFetchRequest。我将fetchBatchSize设置为5,并实现适当的委托方法:

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller

我确保将fetchedResultsController的代理设置为self。但是,我在所有上面的委托方法中都放了一个NSLog语句,并且没有一个被调用。我的fetchRequestController获取计数是204,批量大小是5,所以当我向下滚动表时,是不是应该调用一些委托方法?或者是什么是另一种确保它正常工作的方法?

2 个答案:

答案 0 :(得分:1)

获取控制器应该知道总共有多少个managedobject。我不知道你在哪里检查,但这可能是你204的原因。 此外,只有当你修改你的uitable数据源中的对象时才会调用这些方法,它们与表格本身的滚动无关。

答案 1 :(得分:1)

您应该能够对fetchedResultsController的fetchedObjects数组使用快速枚举,并测试每个NSManagedObject的isFault属性。如果你只要求它返回5,我认为你应该看到5将isFault设置为NO,其余的将isFault设置为YES。

有关isFault属性的信息,请参阅NSManagedObject Class Reference