gpt4 book ai didi

ios - 如何过滤 UICollectionView 并保持键盘向上?

转载 作者:IT王子 更新时间:2023-10-29 08:06:09 26 4
gpt4 key购买 nike

我已将 UISearchBar 添加到 UICollectionView 并在委托(delegate) searchBar:textDidChange: 中过滤我的模型并调用 [ collectionView 重新加载数据]reloadData(以及 reloadSection 等)想要从搜索栏的文本字段中移除 firstResponder,从而关闭键盘。

我正在尝试构建一个“实时更新”过滤器,因此在键入每个字符后让键盘消失是很烦人的。

有什么想法吗?

最佳答案

在searchBar 委托(delegate)函数中,我使用performBatchUpdates,首先,重新加载collectionView 然后调用[self.searchBar becomeFirstResponder] 来显示键盘

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
[self setEditing:NO animated:YES];
[searchBar setShowsCancelButton:YES animated:YES];

[self.collectionView performBatchUpdates:^{
[self.collectionView reloadData];
} completion:^(BOOL finished) {
[self.searchBar becomeFirstResponder];
}];
}

关于ios - 如何过滤 UICollectionView 并保持键盘向上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15255270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com