0
votes

All previous questions are relating to anchoring table view section headers, but I would like to know if its possible to anchor the main header below the navigation bar?

I'm using a UISearchController and adding its search bar to the table header, which appears thus:

enter image description here

But because the header is not anchored it and the search bar will disappear if the user scrolls:

enter image description here

Therefore I want to know if its possible to anchor the table header below that navigation bar? Can't find any previous questions relating to this, only relating to anchoring section headers. Fiddling around with the various storyboard settings such as bouncing and scrolling wasn't fruitfull.

P.S. Any proposed solutions involving manually adding a search bar to a section header and anchoring that instead is I just know going to lead to too much hassle and problems when the search bar becomes active. Using UISearchController and adding its search bar to the table view header nicely animates the navigation bar out of the way and slides the search bar up and down as it gains/loses first responder status:

enter image description here

All this is handled automatically by the UISearchController automatically simply by adding one line of code (to add the search bar to the header). Therefore I don't want to go down the road of replacing all the UISearchController provided functionality with custom table section headers and so on.

1

1 Answers

-2
votes

Have you considered just putting it outside the UITableView?

I believe that would be the easiest and most straightforward solution.

Edit:

Take a look at this solution: Fixed UISearchBar using UISearchController - Not using header view of UITableView

Edit 2:

I figured it out. Here you go!: https://github.com/gorillatech/TableSearchwithUISearchController


My first answer was actually the one that works the best. You just have to add a UIView above the UITableView.

Then you add the UISearchController's searchBar to said view:

[_searchView addSubview:self.searchController.searchBar];