I\'ve added a UISearchBar
to a UICollectionView
and in the delegate searchBar:textDidChange:
filter my model and call [collectio
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];
}