How should I present a UISearchController using a UISplitView adaptive user interface?
Asked Answered
P

1

9

Using a universal storyboard with an adaptive UISplitViewController user interface.

I want to present a search controller on the primary (master) side, using the following code (from the master view controller):

static NSString * const kCGISearchViewControllerID = @"SearchViewControllerID";

- (IBAction)searchButtonClicked:(UIBarButtonItem *)__unused sender {
    SearchViewController *searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:kCGISearchViewControllerID];
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
    self.searchController.searchResultsUpdater = searchResultsController;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    [self presentViewController:self.searchController animated:YES completion:nil];
}

It initially appears to work correctly (regardless of the starting orientation):

Landscape starts out looking ok

Problems show up after autorotation (keyboard still visible, underlying content still dimmed, but the search bar has disappeared):

enter image description here

Upon rotating back to landscape, the search bar reappears, but its width is now wrong:

enter image description here

(I've also tried placing the search controller's searchBar in the titleView. While the searchBar adapts correctly, the search results controller still doesn't look right.)

What am I missing to get a presented UISearchController to animate itself properly as the UI adapts to changing size classes?

Update:

Adding self.definesPresentationContext = YES; gets the search bar/results to appear within the primary view, but the search bar is animating under that navigation bar, and isn't visible. The other issue is that the search bar height doesn't shrink, when it rotates from portrait (which has a status bar), back to landscape.

Phrensy answered 16/1, 2015 at 18:1 Comment(1)
I've gotten a step closer by adding self.definesPresentationContext = YES; The searchBar and results controller now fit within the primary view, but the searchBar is hidden under the navigation bar.Phrensy
S
5

What Xcode version are you using? What iOS version on the simulator?
Tried that using Xcode 6, iOS 8.4 - That's all the code I used in the MasterVC:

class MasterViewController: UITableViewController {

    @IBAction func search(sender: UIBarButtonItem) {
        let searchController = UISearchController(searchResultsController: nil)
        searchController.hidesNavigationBarDuringPresentation = false
        presentViewController(searchController, animated: true, completion: nil)
    }
...
}

It's presented within the Master and locks the orientation of the screen! The behavior might have changed since you posted your answer.

Satiate answered 29/8, 2015 at 8:24 Comment(2)
Probably. Lots of bugs got fixed in 8.3 and 8.4. Thanks for the report. I shipped that app, but will keep it in mind for future apps.Phrensy
Update for iOS 9.2, swift2, xcode 7.2: Tested inside a storyboard Tableview, slight changes to the swift code @IBAction func startSearch() { presentViewController(searchController, animated: true, completion: {})}Hypophysis

© 2022 - 2024 — McMap. All rights reserved.