Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView steals focus

I have a UICollectionView with a header, some cells and a footer supplementary views. The header contains a UISearchBar. If I type something into the search field, the keyboard automatically dismisses after the first letter. I think it is caused by my -searchBar:textDidChange:, which contains code for refreshing the collection view (via -reloadData, because this is the only method I know which works).

My theory is, that reloading the UICollectionView causes it to become first responder, but that somehow does not work.

I have this line in my output every time the keyboard dismisses:

setting the first responder view of the collection view but we don't know its type (cell/header/footer)

I attempted to overwrite UICollectionView's -canBecomefirstResponder, but unfortunately that didn't work.

Any ideas how can I prevent UICollectionView to become the first responder after the reload?

like image 299
gklka Avatar asked Nov 11 '22 23:11

gklka


1 Answers

I've had luck restoring the search bar as the first responder after updating the table view:

collectionView.reloadData()
searchBar.becomeFirstResponder()
like image 95
Dave Batton Avatar answered Nov 15 '22 07:11

Dave Batton