I have a problem with my status bar .
it disappears as soon as i press on my search bar,Look at the examples :
Status bar shows normally before search bar pressed:
Status bar does not show and just disappears out of view:
Thanks ahead ! :)
here is my searchController setup :
override func viewDidLoad() {
super.viewDidLoad()
definesPresentationContext = true
self.resultsController.tableView.dataSource = self
self.resultsController.tableView.delegate = self
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController = UISearchController(searchResultsController: self.resultsController)
self.tableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
self.searchController.dimsBackgroundDuringPresentation = true
self.searchController.searchBar.sizeToFit()
self.searchController.searchBar.barTintColor = UIColor.blackColor()
self.searchController.searchBar.endEditing(true)
self.searchController.searchBar.placeholder = "חפש ברים"
}
Try this setting:
searchController.hidesNavigationBarDuringPresentation = false
And override this function (Swift 2):
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
Related
if #available(iOS 11, *) {
let searchController = UISearchController(searchResultsController: ResultsController())
searchController.searchBar.backgroundColor = UIColor.Custom.theme
searchController.searchBar.delegate = self
searchController.searchResultsUpdater = self
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
}
I want to know how to make searchResultsController stick below searchBar ... Thanks
Solution:
In parent controller:
override func viewDidLoad() {
extendedLayoutIncludesOpaqueBars = true
// Your code
}
override func viewDidLoad() {
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
self.tableView?.tableHeaderView = searchController.searchBar
}
This is default behavior when you add the search bar to tableview header.
There is a code that creates the Search Bar. After there is a click on this Search Bar, then it is shifted down along with the "Cancel" button. I enclose screenshots and code.
before click
after click
#IBAction func showSearchBar(_ sender: UIBarButtonItem) {
self.navigationItem.setRightBarButtonItems([], animated: true)
self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchResultsUpdater = self
self.searchController.searchBar.delegate = self
self.searchController.delegate = self
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.obscuresBackgroundDuringPresentation = true
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.searchBar.placeholder = "Искать продукты"
self.searchController.searchBar.setShowsCancelButton(true, animated: true)
self.searchController.searchBar.searchBarStyle = .minimal
self.navigationItem.titleView = searchController.searchBar
self.definesPresentationContext = true
}
How to fix it?
I showed UIViewController like modal style. UIViewController has UITableView. I added UISearchController to UITableView but UISearchController has incorrect behavior when it disappeared. I made many times UISearchControllers but I didn't face the this behavior.
My code
So I show the UIViewController
#objc fileprivate func selectInterlocutor(_ button: UIButton) {
let selectInterlocutorTVC = SelectInterlocutorTableViewController()
selectInterlocutorTVC.modalPresentationStyle = .overCurrentContext
selectInterlocutorTVC.modalTransitionStyle = .coverVertical
selectInterlocutorTVC.providesPresentationContextTransitionStyle = true
present(selectInterlocutorTVC, animated: true) {
}
}
I add UISearchController to tableView
fileprivate func addSearchController() {
searchController.searchBar.barStyle = .default
searchController.delegate = self
searchController.searchBar.delegate = self
searchController.searchResultsUpdater = self
searchController.searchBar.autocapitalizationType = .words
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
}
Please look at this video that you can see this behavior.
https://www.dropbox.com/s/l3m3q8wmqoy3qv2/SearchBarBug.mov?dl=0
How can I fix it?
I removed UISearchController and I used UISearchBar and it works for me.
fileprivate func addSearchController() {
searchBar.barStyle = .default
searchBar.delegate = self
searchBar.autocapitalizationType = .words
searchBar.showsCancelButton = true
searchBar.sizeToFit()
tableView.tableHeaderView = searchBar
}
I'm trying to use the new UISearchController in my tableViewController.
However I'm a bit confused on how it can move up in the navigationController when I press the searchBar like it did with the old searchDisplayController?
At the moment it just stay in the tableHeader.
Here is my code:
self.teamSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.showsScopeBar = true
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
Controller:
When I click on searchbar:
You can place the UISearchBar of UISearchController in the navigation bar instead of table header
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;
self.definesPresentationContext = YES;
Swift version:
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.searchBar.searchBarStyle = UISearchBarStyle.Minimal
// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar
self.definesPresentationContext = true
It has to do with the navigation bar.
func willPresentSearchController(searchController: UISearchController) {
self.navigationController?.navigationBar.translucent = true
}
func willDismissSearchController(searchController: UISearchController) {
self.navigationController?.navigationBar.translucent = false
}
If you do this, then you will be able to add it to the table view header AND get the baked-in search controller animation!