For some reason, when I set UITableViewController navigationItem.searchController with a UISearchController, it doesn't take it.
Here is my code:
let searchController = UISearchController(searchResultsController: nil)
if #available(iOS 11.0, *) {
print("?", navigationItem.searchController)
print("!", searchController)
navigationItem.searchController? = searchController
print("?", navigationItem.searchController)
} else {
tableView.tableHeaderView = searchController.searchBar
}
Here is the debug window:
? nil
! <UISearchController: 0x105077600>
? nil