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:
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.
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..
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:
- Set a
UISearchBar
as the tableviewstableHeaderView
. - Also add a
UISearchDisplayController
to the table view controller. - 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
精彩评论