extra space between search bar and searchResultsController - ios

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
}

Related

Swift - How to get rid of this dark background in UISearchController?

I got this dark background:
image of the problem
Here are my codes:
class SearchController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate {
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
searchController.searchBar.delegate = self
searchController.searchResultsUpdater = self as? UISearchResultsUpdating
self.definesPresentationContext = true
self.navigationItem.titleView = searchController.searchBar
searchController.hidesNavigationBarDuringPresentation = false
self.definesPresentationContext = true
}
}
What should I do?
Thanks!
Try adding this
searchController.dimsBackgroundDuringPresentation = false
https://developer.apple.com/documentation/uikit/uisearchcontroller

iOS - SearchBar jumping to top as i tap on it to enter text

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.

searchResultsController with a UITableViewController hides the navigation bar, how to prevent it?

When I assign a TableViewController as the constructor for UISearchController, when the table is loaded, it hides the navigation bar (that includes title and search bar). How can I make it, so it doesn't hide it?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureNavigationItem()
}
}
extension ViewController {
private func configureNavigationItem() {
let resultsController = UITableViewController(style: .plain)
navigationItem.searchController = UISearchController(searchResultsController: resultsController)
navigationItem.hidesSearchBarWhenScrolling = false
}
}
Initial Load
Tap Any Key
Found the answer:
definesPresentationContext = true
as in:
private func configureNavigationItem() {
let resultsController = UITableViewController(style: .plain)
navigationItem.searchController = UISearchController(searchResultsController: resultsController)
navigationItem.hidesSearchBarWhenScrolling = false
**definesPresentationContext = true**
}

Status Bar disappearing When Searching

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
}

UISearchController incorrect behavior when it is present modally

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
}

Resources