4

I have searched all other questions about UISearchBar and nothing seems to answer my issue. I have a navigation view at the top and a tableview with a UISearchBar. When I tap on the search bar, the tableview gets darkened, the keyboard comes up, both as they should, but the uisearchbar disappears. If I tap on the darkened out tableview, the keyboard gets dismissed, the darkeness goes away, and the UISearchBar reappears. Any idea why it is disappearing?

Here's some code which is inside a class which extends UITableViewController:

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 44)];
searchBar.delegate = self;
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
//[self.tableView insertSubview:self.searchDisplayController.searchBar aboveSubview:self.tableView];
self.tableView.tableHeaderView = searchDisplayController.searchBar;

In my .h file, I adopt these protocals: ` but I do not implement any of their methods except:

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
[tableView registerClass:[EmailCell class] forCellReuseIdentifier:mailCellIdentifier];
}

EDITED:

I purposely moved the tableview down further, so that there is whitespace between the top navigation view and the tableview, and found that the searchbar wasn't disappearing, it was moving further up on the screen when tapping the UISearchBar, occupying the whitespace that I added in. Any ideas why?

upenn
  • 41
  • 1
  • 5

1 Answers1

-1

Add this method

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
        [self.tableView insertSubview:self.searchDisplayController.searchBar aboveSubview:self.tableView];
    }
}

For more detail check this link

Community
  • 1
  • 1
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
  • That answer seems to be for "search bar disappears after a quick double-tap", not for "search bar goes out of view after selecting it with a single tap", which this question is about. – oh7lzb Jul 19 '14 at 08:13