How to filter UICollectionView and keep keyboard up?

前端 未结 11 1551
旧时难觅i
旧时难觅i 2020-12-30 23:47

I\'ve added a UISearchBar to a UICollectionView and in the delegate searchBar:textDidChange: filter my model and call [collectio

11条回答
  •  长发绾君心
    2020-12-31 00:26

    If you've added the UISearchBar as a header to the UICollectionView the reloadData call will "refresh" the header by removing and re-adding the UISearchBar causing it to lose firstResponder.

    You can either add your UISearchBar in another way, not using header, or override reloadData, check if the search bar is currently firstResponder, and if so after calling super, do:

    // If we've lost first-responder, restore it.
    if ((wasFirstResponder) && (![self.searchBar isFirstResponder])) {
        [self.searchBar becomeFirstResponder];
    }
    

提交回复
热议问题