YosiFZ
YosiFZ

Reputation: 7900

UISearchController UISearchBar is not vissible in IOS 12

I have UISearchController in my app and this is the code I'm using to create it:

-(void)setSearchBar {
    self.resultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    [self.resultsController.tableView registerClass:UITableViewCell.self forCellReuseIdentifier:@"SearchTitleCell"];
    self.resultsController.tableView.dataSource = self;
    self.resultsController.tableView.delegate = self;

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsController];
    [self.searchController setSearchResultsUpdater:self];
    [self.searchController setDelegate:self];

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.1")) {
        self.searchController.obscuresBackgroundDuringPresentation = NO;
    }

    self.extendedLayoutIncludesOpaqueBars = YES;

    self.navigationItem.searchController = self.searchController;

    self.searchController.searchBar.delegate = self;
}

I noticed that in IOS 13 it's working fine, but in IOS 12 I can't see the searchbar as shown in the photos:

IOS 13: enter image description here

IOS 12: enter image description here

Any idea what is the problem?

Upvotes: 1

Views: 168

Answers (1)

Nikaaner
Nikaaner

Reputation: 1320

In iOS 12 the search bar is shown below the results controller. To fix that you have to set self.definesPresentationContext = true for the main controller in your code. You can also do this on a storyboard.

Upvotes: 2

Related Questions