Search code examples
uisearchbaruisearchdisplaycontroller

UISearchBar programatically - Result is displayed over "all records" table


I have an issue with my UISearchBar created programatically in popover (which is a subclass of tableviewcontroller). Everything is working fine but there is one thing which drains my blood. When searching among all records in table - the result is displayed over these all records. Lets see a picture of table which I get after searching for some rubbish.

enter image description here

The scrollable result table (empty) and, as a background, all records table (cannot be clicked). Here goes my code snippets.

CustomerPickerViewController.h

@interface CustomerPickerViewController : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate>{

UISearchDisplayController *searchDisplayController;

}

CustomerPickerViewController.m

//set up searchbar
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchBar.delegate = self;

//set up searchDisplayController with search bar
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;

//place searchBar in the header
self.tableView.tableHeaderView = searchBar;

To make it more obvious, see this search result which is covering full records table. This background table can be seen once I slide first cell down.

enter image description here

How can I have just white background behind my search result?

Thanks a lot.


Solution

  • If your original table view is translucent I think it would give you the result we see on the screenshot. Try changing your original table view background color:

    tableView.backgroundColor = [UIColor whiteColor];
    

    Just for the record, there is no replacement going on for the table views, the table view that presents your search results is being presented on top of your original table view that is being filtered.