How to reload only the UICollectionView data section?

I am trying to reload only the data section, not the header or footer (optional view), UICollectionView.

When I use the reloadData method, the header and footer section also reloads, so what I want.

I found the reloadSections: method, but I do not know why it does not work.

Since my view of the collection contains only one section, so I tried to use this method as follows:

 [collectionViewController.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; 

But when the method is called, a runtime error occurs. Error Content:

 'NSInvalidArgumentException', reason: '-[UICollectionViewUpdateItem action]: unrecognized selector sent to instance 0x90aec00' 

Is it not possible to use the reloadSections: method? Is there an alternative way to reload a data section rather than a header or footer section?

+4
source share
1 answer

I think that an error occurs only when the search bar is a preview of the collection view and tries to call reloadSections: when entering the keyboard.

This article provides an answer to a similar problem, but this did not work for me.

So, I used an alternative method by which you can call almost the same function.

Instead of adding a title as an additional view, I made the title a preview of "view". (not collectionView)

And added a scroll delegate to simulate a table title.

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat y = scrollView.contentOffset.y; if (y < 44) { [self.searchBar setFrame:CGRectMake(0, -y, 320, 44)]; [self.searchBar setHidden:NO]; } else if (y >= 44) { [self.searchBar setHidden:YES]; } } 
+6
source

All Articles