UISearchController hides results above the search bar
Asked Answered
D

1

7

I am using a UISearchController inside a Container view in a UITableView. I am adding the search bar like this:

self.resultsTableController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ResultViewController class])];

self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsTableController];
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.searchController.searchResultsUpdater = self;
[self.searchController.searchBar sizeToFit];

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.resultsTableController.tableView.delegate = self;
self.searchController.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
self.searchController.searchBar.delegate = self;
self.definesPresentationContext = NO;

See the following screenshots. It hides all the search results that are above the search bar:

original image when searchbar is not active. SearchBar active and all above elements get hidden.

Please help me out why i am getting this?

Debrahdebrecen answered 31/3, 2015 at 20:9 Comment(0)
P
1

I found searchcontroller is little tricky. I had lot of issues and I found that specific order matters. The following combination is what worked for me

        searchController.searchResultsUpdater = self
        searchController.searchBar.delegate = self
        searchController.dimsBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = "search"
        searchController.searchBar.returnKeyType = .done
        searchController.searchBar.searchBarStyle = .minimal
        searchController.hidesNavigationBarDuringPresentation = false
        searchController.searchBar.sizeToFit()
        definesPresentationContext = true
        if(tableView.tableHeaderView == nil){
            tableView.tableHeaderView = searchController.searchBar
        }

You can have

searchController.hidesNavigationBarDuringPresentation = false
Plush answered 22/10, 2019 at 23:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.