UISplitViewController with new UISearchController issue with UISearchBar

I recently started rewriting an iOS app to use the new UISearchControllerand universal storyboard. My application is available for both devices (iPhone and iPad), so changing the universal storyboard using UISplitViewControllerwas a big advantage.

But, unfortunately, it UISearchControllerdoes not work as expected. I added UISearchControllerwith the following lines:

self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchBar.sizeToFit()
self.searchController.dimsBackgroundDuringPresentation = false
self.myTableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
self.definesPresentationContext = true

My controller chain is this:

UISplitViewController
    UITabbarController (Master)
        UINavigationController
            UITableViewController
    UINavigationController (Detail)
        UINavigationController
            UIViewController

The problem is that the iPad application is UISearchBarcovered UINavigationBar. But if I switch the tabs and get back to view. Is displayed UISearchBar. So somehow, after switching tabs, he correctly redraws the view. In the iPhone version, it is automatically fixed.

iPad App

UISearchBar UINavigationBar

After the first launch the UISearchBar is covered by the UINavigationBar

UISearchBar

After switching the tabs the UISearchBar is displayed correctly

iPhone App

iPhone , . iPhone App works as expected

:

  • Edges
  • SearchController viewWillAppear, , ,
0
1

, self.searchController.searchBar.sizeToFit() viewDidload. , (Objective-C code):

- (void)viewDidLayoutSubviews {
    // you could check
    // if (IS_IPAD || (IS_IPHONE_6PLUS && UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))) 
    [self.searchController.searchBar sizeToFit];
}

, viewDidlLoad viewDidLayoutSubviews:

self.edgesForExtendedLayout = UIRectEdgeNone;
self.yourTableViewController.edgesForExtendedLayout = UIRectEdgeNone;

, ,

0

Source: https://habr.com/ru/post/1687463/