I have a UICollectionView
that have section header. In the section header I have a UISearchBar
. I want to filter the content in my collection view
did you tried with one of this options?
To reload just the new items
[self.collectionView reloadItemsAtIndexPaths:indexPaths];
To reload the complete section
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
Or, if it doesn't work.. make searchBar first responder again after your updates
[self.collectionViewPackages performBatchUpdates:^{
[self.collectionView reloadData];
} completion:^(BOOL finished) {
[self.searchBar becomeFirstResponder];
}];
I finally figured this out after trying many different options. The solution is to make your header of its own section so you can reload the other sections independently without reloading the one your header is attached to.
So:
Then, we you need to reload your data:
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
Your searchbar or text fields should retain their focus while the user is typing and you can update the results in the background.