1
votes

I have a table view controller inside a navigation controller, and on viewDidLoad I add some views to the table view header :

//Build up master container view with search bar and another view that has buttons
...

//Set this as the table header
self.tableView.tableHeaderView = masterHeaderContainerView;

If I do nothing else at this point my view from top to bottom looks like

Navigation bar, Search bar, Action bar with buttons, Table View cells... https://www.dropbox.com/s/mwhipz5qpa9duzw/filterAndActions.PNG

However, I want to hide the search bar under the navigation bar, so I set the content offset of the table view in viewWillAppear

self.tableView.contentOffset = CGPointMake(0, self.searchBar.frame.size.height);

On iOS 6 this worked fine, but on iOS 7, when I then scroll down to reveal the search bar, it's vanished, there's a blank space where it should be.

What might give a clue to the problem is that if I hard code the content offset to 22 (half the height of the search bar), and then scroll down, the search bar has been half hidden by what looks like the background.

https://www.dropbox.com/s/jm1vro769jfhpy8/halfFilterBar.PNG

So the amount by which I set the content offset is the amount by which the search bar is covered. Any ideas what might be going on here?

The goal is to have a filter bar like the Mail app, that's hidden under the navigation bar when the view first appears, but can be revealed by scrolling down.

I'm building the search bar and search display controller programmatically, as the view has no xibs / storyboard, it's a standard UITableViewController subclass.

UISearchBar *aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
UISearchDisplayController *aSearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:aSearchBar contentsController:self];
aSearchBar.frame = ...
2

2 Answers

2
votes

You should set to get the expected behavior in iOS 7

self.edgesForExtendedLayout = UIRectEdgeNone;
1
votes

add this

 [self.view bringSubViewToFront:aSearchBar];

also

[self.tableView setClipsToBounds:YES];