当我进入PhotoVC时,我第一次没有更新数据 NSFetchRequestController 。比方说,我有摄影师和照片实体,分别是一对多关系“一位摄影师可以有多张照片”,
当我点击摄影师单元格时,它会将我带到photosVC,在后台,我会更新照片实体,但NSFetchResultController不会显示结果。然而,当我回击并回到PhotoVC时,它向我显示数据......不确定为什么 NSFetchResultController 第一次没有更新?
我使用下面提到的FetchResultCOntroller代码
- (NSFetchedResultsController *)fetchedResultController
{
if (!_fetchedResultController) {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Photo"];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"Photos.PhotographerID = %@",];
fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"timeStamp" ascending:YES]];
//[fetchRequest setFetchBatchSize:20];
_fetchedResultController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:moc
sectionNameKeyPath:nil cacheName:nil];
_fetchedResultController.delegate = self;
}
return _fetchedResultController;
}