我有一个UICollectionView有节标题.在标题标题中,我有一个UISearchBar.我想在搜索栏中输入时过滤我的集合视图中的内容.我用以下方法执行此操作:
// 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];
}
Run Code Online (Sandbox Code Playgroud)
每次搜索栏文本更改时都会调用此方法.这条线[self.collectionView reloadData]为每个角色隐藏了键盘.是否可以仅重新加载UICollection视图中的数据而不重新加载补充视图,如节标题标题?
我的collectionView中的数据来自NSFetchResultController. …