1

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.

Viktor Kucera
  • 6,177
  • 4
  • 32
  • 43
  • 1
    You didn't ask any question. – lawicko Nov 08 '13 at 14:46
  • Man, obviously I don't wanna to display both results. Just empty table with "No Results" in this particular case. – Viktor Kucera Nov 08 '13 at 15:04
  • Could it be that your cell background and/or table view background is translucent? The SearchDisplayController uses the same cells as the original table view, so I guess that could give you the effect we are seeing on the screenshot. – lawicko Nov 08 '13 at 15:11
  • I see your point but - the problem is that background "all records" table is displayed. It should be replaced by my search result. Why? Because when you would scroll on top I mean really on top (for that bounce effect) you will reveal next table in the background. Same goes for bottom bounce. – Viktor Kucera Nov 08 '13 at 15:20
  • Actually I'm pretty sure you are wrong. There is no replacement going on here, the table view that presents your search results is being presented on top of your original table view that is being filtered. Also, I checked my sample project to see if the problem described in your last comment exists, and there is no such problem. So if your original table view is translucent I'm still of the opinion that it would give you the result we see on the screenshot. – lawicko Nov 08 '13 at 16:18
  • Thanks for looking at it. Check this http://postimg.org/image/sm8vph5t1/. You can see first cell of full records table behind the first cell of search result. The thing is that its outside of search result table. So even if I set up tableview to being non-translucent how would it affect that "behind" cell (table) which is just covered by search result? Or can I somehow set up background behind the table? – Viktor Kucera Nov 08 '13 at 18:20
  • tableView.backgroundColor = [UIColor whiteColor] helped me. Answer my question and I will accept it. Thanks man! – Viktor Kucera Nov 10 '13 at 20:51
  • I'm glad my advice actually helped you to find the solution, I added the answer in case somebody else has the similar issue. – lawicko Nov 11 '13 at 21:41

1 Answers1

1

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.

lawicko
  • 7,246
  • 3
  • 37
  • 49
  • 1
    It worked, thanks bud! Some useful information on topic can be found here http://stackoverflow.com/questions/19030303/ios-7-uisearchdisplaycontroller-not-cleaning-background-when-search-data – Viktor Kucera Nov 12 '13 at 09:15