I added SearchBar
to my TableView
in ViewDidLoad()
doing it:
self.searchBar = UISearchController(searchResultsController: nil)
self.searchBar.searchResultsUpdater = self
self.searchBar.dimsBackgroundDuringPresentation = false
self.searchBar.searchBar.sizeToFit()
self.tableView.tableHeaderView = self.searchBar.searchBar
self.tableView.reloadData()
everything works fine, but when I tap on this SearchBar
it disappears. It means, I can still typing, and I can see the results but, don't see SearchBar
. I implemented UISearchBarDelegate
and I have been trying to add
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
self.navigationController?.navigationBarHidden = false
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
self.navigationController?.navigationBarHidden = true
}
but it still doesn't work. Do you have any idea, why this Search Bar
disappears?
solution of this problem is (like @sandy sad) write this line of code in viewDidLoad()
self.aNavigationController?.extendedLayoutIncludesOpaqueBars = true
but now I have a new problem it's mean When I select row in TableView
and display new VievController
, SearchBar
doesn't disappear and I see it in new view. Why?
You need to set extendedLayoutIncludesOpaqueBars to true in viewDidLoad().
self.aNavigationController?.extendedLayoutIncludesOpaqueBars = true