问题描述
我已将 UISearchBar
添加到 UICollectionView
,并在委托 searchBar中添加: textDidChange:
过滤我的模型并调用 [collectionView reloadData]
。 reloadData
(以及reloadSection等)想要从搜索栏的文本字段中取走firstResponder,从而解雇键盘。
任何想法?
在searchBar委托函数中,我使用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];
}完成:^(BOOL完成){
[self.searchBar becomeFirstResponder];
}];
}
I've added a UISearchBar
to a UICollectionView
and in the delegate searchBar:textDidChange:
filter my model and call [collectionView reloadData]
. reloadData
(as well as reloadSection, etc) wants to take away firstResponder from the searchbar's textfield, thus dismissing the keyboard.
I am trying to build a "live updating" filter and so it's annoying to have the keyboard go away after each character typed.
Any ideas?
In searchBar delegate function , I use performBatchUpdates, first,reload collectionView then call [self.searchBar becomeFirstResponder] to display keyboard
- (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];
}];
}
这篇关于如何过滤UICollectionView并保持键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!