Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,24 @@ - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
// ---------------

if (hasChanges) {

if (self.hasOffsetOrLimit) {


__block BOOL needsReload = self.hasOffsetOrLimit;
// WORKAROUND: Workaround a problem in the implementation difference of
// UICollectionView and NSFetchedResultsController
[self.deletedItems enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
if (indexPath.section < self.collectionView.numberOfSections) {
needsReload = ([self.collectionView numberOfItemsInSection:indexPath.section] == 1);
*stop = needsReload;
}
}];
[self.insertedItems enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
if (indexPath.section < self.collectionView.numberOfSections) {
needsReload = ([self.collectionView numberOfItemsInSection:indexPath.section] == 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never happen, as a fetched results controller will never return a section without an item.

*stop = needsReload;
}
}];

if (needsReload) {
// WORKAROUND: If the fetch offset or fetch limit is set, the collection view needs to reload,
// because the NSFetchedResultsController ignors this while handling the updates.

Expand Down