如何过滤 UICollectionView 并保持键盘正常运行? [英] How to filter UICollectionView and keep keyboard up?

查看:14
本文介绍了如何过滤 UICollectionView 并保持键盘正常运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

有什么想法吗?

推荐答案

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

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 并保持键盘正常运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆