Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting UITableView contentInset also insets section header view

I'm changing my tableviews contentInset, so that when a user scrolls beyond the top bounds of the table, the tableview is inset to display a UISearchBar hidden above the tableView.

Everything works fine apart from the section header views. when scrolling down, the top bound of the sectionHeaderView is inset the same distance from the top of the screen as my tableview inset, here is it in starting position:

Header view in correct position

In the above image the sectionheader view is set to its correct positon, and the tableview inset has been set to display the search field.

enter image description here

You can see in this second screenshot where the top bound of the headerview is set lower because of the 43 pixel tableview inset, where as it should stick to the top of the screen hiding the "related" cell and bouncing back when released.

I guess i need to Offset the Inset somehow, i'm just not sure how..

like image 784
Alex Avatar asked May 13 '11 14:05

Alex


1 Answers

I am assuming what you want is a search field like in the Mail application; a search field at the very top of the list that by default is not visible?

The solution is not to use contentInset, but instead:

  1. Set a UISearchBar as the tableviews tableHeaderView.
  2. Also add a UISearchDisplayController to the table view controller.
  3. By default set the contentOffset to 44 points down, to hide the search bar.

Apple has a good sample app as a starting point here: http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html

like image 51
PeyloW Avatar answered Nov 04 '22 19:11

PeyloW