NSFetchedResultsController refresh refetch?

前端 未结 3 1402
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 08:44

I want to refetch data from my NSFetchedResultsController using a different predicate which is set using a boolean value. How do I refresh NSFetchedResultsController to fetc

相关标签:
3条回答
  • 2020-12-08 09:21

    I had similar problem, I couldn't figure out why my collection view doesn't refresh its cells. Adding the method below fixed my problems.

    -(void)didUpdateObjectAtIndexPath:(NSIndexPath *)indexPath{
        UICollectionView *strongCollectionView = self.collectionView;
        [strongCollectionView  reloadItemsAtIndexPaths:@[indexPath]];
    
    
    }
    
    0 讨论(0)
  • 2020-12-08 09:30

    Don't forget to set fetchedResultsController = nil before performFetch. Otherwise it will use the old one.

    0 讨论(0)
  • 2020-12-08 09:34

    Here's how we do it in an application:

    // Assuming these exist
    NSPredicate * predicate;
    NSString * cacheName;
    
    [[fetchedResultsController fetchRequest] setPredicate:predicate];
    [NSFetchedResultsController deleteCacheWithName:cacheName];
    
    NSError * error = nil;
    [fetchedResultsController performFetch:&error];
    if (error) {
        // report error
    }
    
    0 讨论(0)
提交回复
热议问题