Clicking a view controller while presenting a UISearchController over a UINavigationBar

I implemented UISearchControllerit to display a caption UINavigationBarwhen you click the search icon. After filtering the table, the user should be able to select the row that will invoke the new view controller. The problem is that the search controller is still displayed on top of the navigation bar.

I researched this, and was asked to install self.definedPresentationContexton true. This does not work when the search bar is displayed over the navigation bar. When you click the search icon, a keyboard appears, but the search bar does not enliven.

Another option I found is to reject the search controller in viewWillDisappearby setting activeto false. The problem with this solution is that it comes to life during the transition. And when you go back, the search is obviously already inactive, so the user has lost the search context, and all the results are shown.

I would like to know how to click the view controller, keep the search active, but not show the superscript interface of the next controller search interface. Ideally, the search interface will be dropped to the left when the new view controller is clicked, and go back to return to the search results.

I modified the Apple UIKit example code sample to show unwanted behavior. To reproduce the problem, download this project , launch it on the iPhone, click the "Back" button, select "Search", select the "Up", click the "Search" icon, enter a search query and select a result. Please note that the search bar remains visible. Here is the code from SearchPresentOverNavigationBarViewController.swift:

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)

    if searchController.active {
        //searchController.active = false //undesirably dismisses search, animates away during push, upon going back search is not active
    }
}

@IBAction func searchButtonClicked(button: UIBarButtonItem) {
    //self.definesPresentationContext = true //causes the search to not appear

    searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.hidesNavigationBarDuringPresentation = false

    presentViewController(searchController, animated: true, completion: nil)
}
+4
source share
1 answer

I was a bit late for the show, but recently I found myself in a similar situation and I want to share my experience.

, , , - , . , , , . , , "", ( ).

, , , , , .

, , , - , . , . , , . !

0

All Articles