I am trying to add a UISearchController to a UIViewController that contains a UITableView (and MKMapView too, but hopefully this is not a problem). I followed the Ray Wenderlich tutorial , but I cannot get the same result in terms of behavior.
Here is my viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = NSLocalizedString("Search references by project, customer or city", comment: "")
if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
} else {
tableView.tableHeaderView = searchController.searchBar
}
definesPresentationContext = true
self.modeSelector.layer.cornerRadius = 5.0
if let split = splitViewController {
let controllers = split.viewControllers
detailViewController = (controllers[controllers.count - 1] as! UINavigationController).topViewController as? ReferenceViewController
}
self.navigationItem.rightBarButtonItem?.isEnabled = false
}
Please note that the #available test in the middle is what I need to support iOS up to 9.1.
Now I see a few problems:
- The search bar appears immediately, and I cannot hide it by scrolling
- When I focus the search bar, the top of the table does not snap to the bottom of the navigation element:

, Ray Wenderlich, , , XCode 9, , . , , , .
, ?