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 when I type in the search bar. I do this with the following method:
// The method to change the predicate of the FRC
- (void)filterContentForSearchText:(NSString*)searchText
{
NSString *query = searchText;
if (query && query.length) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@ or createdAt contains[cd] %@ or noteText contains[cd] %@ or keywords contains[cd] %@", query, query, query, query];
[self.fetchedResultsController.fetchRequest setPredicate:predicate];
} else {
[self.fetchedResultsController.fetchRequest setPredicate:nil];
}
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
// Handle error
NSLog(@"Error");
}
[self.collectionView reloadData];
}
This method gets called every time the search bar text changes. The line [self.collectionView reloadData]
hided the keyboard for every character. Is it possible to reload only the data in a UICollection view and not reload the Supplementary views like section headers headers?
The data in my collectionView comes from a NSFetchResultController.
I'm pretty happy with how my UI works so if there is a simple way to NOT reload the section header, then that would be great!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…