开发者

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:

Setting UITableView contentInset also insets section header view

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.

Setting UITableView contentInset also insets section header view

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:

  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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜