Strange things seem to happen when using the new iOS 11 navigationItem.searchController
method on a detail view of a UISplitViewController
.
The searchBar
partly appears as a blank space on the first presentation, then appears in the wrong UITableViewController
, but corrects itself after a few push and pops of UITableViewController
.
I used to put the searchBar
in the tableHeaderView
, but I changed the code according to the WWDC recommendation:
if (@available(iOS 11.0, *)) {
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
} else {
self.tableView.tableHeaderView = self.searchController.searchBar;
}
This example is using standard sample code (default project for UISplitViewController
and the Apple demo of UISearchController
updated for iOS 11 (using a single UITableViewController
)).
The initial view containing the searchController
looks like this:
And clicking a UITableView
item yields this:
However after clicking on a UITableView
item and returning twice - it looks as it should:
and:
I was trying to determine why the Apple example for UISearchController
worked and my code didn't. The main difference was it was embedded in UISplitViewController
in the Detail View. Which means if shown in Compact mode has an extra UINavigationController
in the stack. I found if my seque avoided the extra UINavigationController
- it works correctly (but breaks device rotation). Similarly change the segue to modal allows it to work.
I note this is similar to this old question: UISplitViewController with new UISearchController issue with UISearchBar
I have created a sample project that demonstrates the problem (sample code: searchControllerDemo)
I'm stumped as to what is going on. So any help would be very much appreciated.
prefersLargeTitles
. On iPhone: A blank space appears in the detail view controller in place of the large title. Upon scrolling the table view upward the title appears normally in the regular size as in iOS 10... On iPad: Everything works like a charm. I played around with the Master-Detail app template and everything seems to be working perfectly on both devices, the large titles search controller – LegionaryUISearchBar
somehow... I actually want to embed one myself in the detail view controller too but will look into this later... There is a lot complexity with theUISplitViewController
. I have included a call to a function that sets up the view (incl. large titles) to a calculated property in the detail view controller. So Upon setting this property in the master view controller, the view is setup correctly with the large title. The view setup function still gets recalled again in theviewDidLoad
– Legionary+[CATransaction synchronize] called within transaction
– LegionaryUISearchController
in the detail view controller insideprepareForSegue
in the master view controller. On the iPad, both master and detail VCs are loaded together hence no problems, same for landscape on iPhone wide screens. – LegionarytableHeaderView
) work instead of battling with this approach: using uisearchcontroller with uisearchbar in tableheaderview in ios11. – Striction