0
votes

I am adding a dynamically scrolling UISearchBar to the top of a tableview. To do this, I have added the UISearchBar as a subview of the tableview and then implemented a scrollviewdelegate method so that the searchbar stays pinned to the top at all times. I also set the contentInset of the tableView accordingly so that the top most cell is offset enough for the searchbar.

The only issue I'm having is with the default separator that's drawn above the first cell in the tableview. When starting at the top, and scrolling down, the separator is actually drawn above the search bar, instead of below it. This creates for a horrible user interface bug that I'd like to fix. Note that this only happens with the first cell; every other separator between cells scrolls under the searchbar, as it should, and does not have the same UI bug. Any thoughts?

enter image description here

1

1 Answers

1
votes

Are you certain that the UISearchBar is frontmost? Try bringing it all the way to the front in code, in your viewDidLoad. If that doesn't work to solve the glitch, consider an alternative solution to your interface. Here are some - try any one of them:

  • Make the UISearchBar the header for the UITableView (not a section; the table view itself). This is very standard interface.

  • If you are on iOS 6, instead of the scroll view delegate trick (which was quite standard before iOS 6, well done), use constraints to pin the search bar to a view higher up the view hierarchy than the table view. (Since you are in a navigation controller, that would be the navigation controller's view in your case.) That's the new iOS 6 way to prevent a scroll view subview from being scrolled with the content. I do not know if that will solve the glitch but it could be worth a try.

  • Don't use the default separator. It is not difficult to draw your own separator as part of the cell background image.