ios – UICollectionView reloadData在section header中重新指定第一个响应者

ios – UICollectionView reloadData在section header中重新指定第一个响应者,第1张

概述我有一个UICollectionView有部分标题.在section header中有一个UISearchBar.当我输入搜索栏时,我想过滤收藏视图中的内容.我用以下方法做到这一点: // The method to change the predicate of the FRC- (void)filterContentForSearchText:(NSString*)searchText{ 我有一个UICollectionVIEw有部分标题.在section header中有一个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];        [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];}

每次搜索栏文本更改时都会调用此方法. [self.collectionVIEw reloadData]行为每个字符隐藏键盘.是否可以仅重新加载UICollection视图中的数据,而不是重新加载补充视图,如段标题头?

我的collectionVIEw中的数据来自一个NSFetchResultController.

我很高兴我的用户界面如何工作,所以如果有一个简单的方法来不重新加载部分标题,那将是非常好的!

解决方法 尝试了许多不同的选择后,我终于明白了这一点.解决方案是使您自己的部分的标题,以便您可以独立重新加载其他部分,而无需重新加载头部附加到的部分.

所以:

>第0节

>标题

>搜索栏(或其他文本字段)

>行

>(无)

>第1节

>标题

>创建一个空的UICollectionReusableVIEw并覆盖… sizeforItemAtIndexPath:(NSIndexPath *)indexPath返回CGSizeZero

>行

>您的实际行,最初将与第0节

然后,我们需要重新加载数据:

[collectionVIEw reloadSections:[NSIndexSet indexSetWithIndex:1]];

您的搜索栏或文本字段应该在用户打字时保留焦点,并且可以在后台更新结果.

总结

以上是内存溢出为你收集整理的ios – UICollectionView reloadData在section header中重新指定第一个响应者全部内容,希望文章能够帮你解决ios – UICollectionView reloadData在section header中重新指定第一个响应者所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1108377.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存