I am facing issue with navigation bar. I'm adding searchController
in navigationItem's search controller.
See the images on following link: navigation bar issue
Steps:
1) I have data in table view, when I click on cell it's open details screen with custom navigation view. This is working fine. (default navigation bar is hidden)
2) Now, I have clicked on search bar and then click on table view cell. It's show me default navigation bar to details screen. I don't want to display default navigation bar.
Code that I did write to implement search controller is as follows:
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search here..."
searchController.searchBar.tintColor = .white
searchController.searchBar.barTintColor = .white
if let textfield = searchController.searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = UIColor.blue
if let backgroundview = textfield.subviews.first {
// Background color
backgroundview.backgroundColor = UIColor.white
// Rounded corner
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
self.navigationItem.searchController = self.searchController
definesPresentationContext = true
Below is code to hide navigation bar inside didSelect method:
self.navigationController?.navigationBar.isHidden = true
self.navigationController?.isNavigationBarHidden = true
tableView(_ tableView: didSelectRowAt indexPath: )
? – Undone