I have a UISearchController
in the navigation bar and it worked fine until now.
Only on iOS 9 the search bar refuse to be the first responder after the controller is loaded.
The code in viewDidLoad
:
self.searchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.delegate = self
controller.dimsBackgroundDuringPresentation = false
let ownSearchBar = controller.searchBar
ownSearchBar.searchBarStyle = .Default
ownSearchBar.barStyle = UIBarStyle.Black
ownSearchBar.placeholder = NSLocalizedString("Search", comment: "Search")
ownSearchBar.showsCancelButton = true
ownSearchBar.sizeToFit()
ownSearchBar.delegate = self
controller.searchBar.delegate = self
controller.hidesNavigationBarDuringPresentation = false
self.navigationItem.titleView = controller.searchBar
self.navigationItem.hidesBackButton = true
self.navigationController?.navigationBar.sizeToFit()
return controller
})()
The code in viewDidAppear:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.searchController.active = true
self.searchController.searchBar.text = state.term
self.segmentedControl.selectedSegmentIndex = state.searchType
}
And my code in didPresentSearchController
:
extension SearchController : UISearchControllerDelegate {
func didPresentSearchController(searchController: UISearchController){
self.searchController.searchBar.becomeFirstResponder()
xButtonWasPressed = true
}
}
Please help me find why only in iOS 9 the search bar don't get the focus