So I have the following setup.
InitialViewController(VC) -> NavigationController -> ViewController1(VC1) contains a UISearchController, displays results in a new controller ViewController2(VC2) -> Segue from a cell click on VC2 -> Launch ViewController3 (VC3)
I need to dismiss VC3 and come back to VC1. However, neither VC2 nor VC3 are part of the navigation controller stack. I have pretty much tried all the suggested alternatives but of no avail.
How do I push the UISearchcontroller and the results on to the navigation stack ?
I am instantiating my UISearchController in VC1 like this:
searchController = UISearchController(searchResultsController:
searchResultsController)
searchController!.searchResultsUpdater = searchResultsController
searchController?.delegate = self
searchController!.obscuresBackgroundDuringPresentation = true
searchController!.searchBar.placeholder = "Search stocks"
searchController?.hidesNavigationBarDuringPresentation = false
definesPresentationContext = true
searchController!.searchBar.delegate = searchResultsController
//navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
navigationItem.titleView = searchController?.searchBar
definesPresentationContext = true
And my searchResultsController:
extension WatchListTableViewController: UISearchResultsUpdating, UISearchBarDelegate {
// MARK: - UISearchResultsUpdating Delegate
func updateSearchResults(for searchController: UISearchController) {
// TODO
filterContentForSearchText(searchController.searchBar.text!)
}
}
class WatchListTableViewController: UITableViewController {
var stocks = [String]()
var filteredStocks = [String]()
override func viewDidLoad() {
super.viewDidLoad()
stocks = ["Apple", "Google", "Microsoft", "Tesla"]
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}