Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search controller below navigation item prior to iOS 11

Tags:

ios10

swift

ios11

I am using this code with no problem, but I would like to place the search controller below the navigation item’s titleView, instead of replacing it. With iOS11 it’s as easy as setting navigationItem.searchController to the searchController, and it will place it below the titleView, but in the navigationItem.

Any ideas on how to do this prior to iOS 11, instead of replacing the titleView?

Current Code:

if #available(iOS 11, *) {
    navigationItem.searchController = searchController
    navigationItem.hidesSearchBarWhenScrolling = false
} else {
    navigationItem.titleView = searchController.searchBar
}
like image 437
Alec O Avatar asked Oct 01 '17 17:10

Alec O


1 Answers

I don't know if it's still relevant for you, but for anyone searching an answer and ending up here, this is a way to do it:

if #available(iOS 11.0, *) {
   navigationItem.searchController = searchController
} else {
   tableView.tableHeaderView = searchController.searchBar
}
like image 191
Holger Avatar answered Sep 30 '22 17:09

Holger