I have a UICollectionView
that displays content from an NSFetchedResultsController
. The collectionView has one section, and in that section there's a header. The header allows the user to filter the content in the collection view. The header view's delegate is connected to the UIViewController
containing the collection view.
As soon as the user changes one of the filter options, the header view fires a message to its delegate. The delegate changes the predicate on the fetchRequest
of its NSFetchedResultsController
and calls -[NSFetchedResultsController performFetch:]
. Next, the collection view has to be notified that the content has changed. This can be done in several ways, but the way I prefer is by calling -[UICollectionView reloadData]
. Unfortunately this method does not work like expected: the entire collection view disappears when I call this method. These are some of the observations I made regarding this issue:
hidden
flag set to YES
. I tried to trace what method caused this by setting a symbolic breakpoint on -[UIView setHidden:]
. Unfortunately it never breaks inside a UICollectionView
subview.collectionView:cellForItemAtIndexPath:
is never called after calling -[UICollectionView reloadData]
.collectionView:viewForSupplementaryElementOfKind:atIndexPath:
is never called after calling -[UICollectionView reloadData]
.numberOfSectionsInCollectionView:
is still called and still returns the correct number (1 in this case).collectionView:numberOfItemsInSection
is still called and still returns the correct number (1 in this case).What I have tried so far to solve the issue:
sectionInset
, itemSize
) on the UICollectionViewFlowLayout
instanceseparatorInset
) on the UICollectionView
instanceUICollectionView
and setting the contentInset
accordingly. Unfortunately UICollectionView
does not like me to temper with its auto layout constraints and crashes when I do so.[UICollectionView reloadSections:]
instead of [UICollectionView reloadData]
. This works but I don't like the animation.-[UICollectionView dealloc]
.It does not feel right to have the header setup this way, but unfortunately UICollectionView
does not have a global header like UITableView
(tableHeaderView
).
Try to Reload them in the main thread
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
});
it worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With