UISearchController disappearing - Master/Detail Setup

Hi All, I've had a hunt in the forums and couldn't find anything related to this, apologies if I've missed it.


I have a Master/Detail app and I'm implementing a UISearchController for the master tableview. I've defined the searchcontroller with this property.

    let searchController = UISearchController(searchResultsController: nil)


I've configured the searchcontroller with this in viewDidLoad. This is the only configuring I'm doing...

     // Configure the Search functionality
     searchController.searchResultsUpdater = self
     searchController.obscuresBackgroundDuringPresentation = false
     searchController.searchBar.placeholder = "Search Items"
     navigationItem.searchController = searchController
     definesPresentationContext = true


All well and good and I have the searching working great.


Problem is when I select an item and go to the item (the detail side is a tabviewcontroller) and then back to the master view the Search Controller is no longer visible.


When I load the app the navigation bar contains the searchcontroller as well as a couple of buttons. When I come back to the master view from the detail side of things - the navigation bar has shrink down to just containing the buttons. There is a slight pause (0.5 seconds) then the tableview moves down the view by about the distance required to hold the searchcontroller.


I've checked and the searchcontroller remains initialised through the above so it's there(!) - just not being displayed.


On the detail side, the tabbarcontroller is embedded in a navigationcontroller and all the tabs are, again, embedded in navigationcontrollers. I've been at this for hours and I just can't see what I've done to cause the searchcontroller to dissapear.


Anyone any ideas. (hope this makes some kind of sense!)


Pat

>When I come back to the master view from the detail side of things


Might want to confirm your presumed logic - I'd expect the UI goes forward, not back, in that example.


You're imagining A<>B, but the UI is doing, by design, A>B>X(?)>...


Otherwise, be sure you've done your best to honor what Apple refers to as 'order of containment'. I'd want to know everything is ok in that example, first, then work on getting your UISC to behave. SVCs can be tricky.

Accepted Answer

and would you believe it was as simple as adding this to my ViewDidLoad code...


navigationItem.hidesSearchBarWhenScrolling = false


😮 - my debugging techniques really need work!

UISearchController disappearing - Master/Detail Setup
 
 
Q