title: Maintaining the first responder status of a view in a custom UICollectionViewLayout across data reloads
body: <p>I am developing a <code>UICollectionViewLayout</code> from scratch. I want to implement a staggered grid layout, aka Pinterest layout. I know, there are many out there, but pretty much all of them support only static item heights, while I would like the item heights to be calculated dynamically.</p>
  
  <p>I got the layout process to work correctly, but now I stumbled upon a problem. I would like to  add a search bar to the section header. The problem is that whenever I call <code>collectionView.reloadData()</code> the search bar loses the first responder status (while maintaining other state, such as the current value).</p>
  
  <p>I tried the usual workarounds (like calling the <code>searchBar.becomeFirstResponder()</code> immediately after <code>reloadData()</code>), but it didn't help. Another workaround is to keep the header with the search bar and items in separate section and only reload the section with items, but my layout currently supports only one section, and it would be nice to know if this will actually solve the problem before spending time to implement support for multiple sections (which I otherwise do not need).</p>
  
  <p>What is causing the search bar to lose the first responder status and how do I prevent this?
  I don't have much experience with custom <code>UICollectionViewLayout</code>s, so I would also appreciate any information about what happens under the hood (when data is reloaded and in general).</p>