views:

254

answers:

1

Hi,

I have a search bar in my main screen - root table view controller. If I browse other screens and come back, sometimes, the search bar disappears. Here's my code.

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44.0)];
    searchBar.delegate = self;
    searchBar.tintColor = [UIColor blackColor]; 
    [searchBar sizeToFit];
     self.tableView.tableHeaderView = searchBar;

    searchDisplayController = [[UISearchDisplayController alloc]
                                  initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;
    searchDisplayController.searchResultsDelegate = self;

Is there anything wrong with my code or is it one of the quirks of SDK 3.0?

A: 

I stumbled across this same issue recently and was able to narrow it's occurrence down to only when the search bar is out of sight (i.e. the table view has been scrolled), then navigated away from, then return to and scrolled back into sight. I have been unable to find any information on what the cause is, but I was able to workaround it by placing this:

self.tableView.tableHeaderView = searchBar;

in either the viewWillAppear or viewDidAppear event of my controller class. I'm assuming the code you've posted is from the viewDidLoad method of your controller class?

thunderbstorm