Question

I have a weird requirement, or at least something I have never done before... I have a UITableView, the header of that table is a UISearchBar. If you tap on that searchbar the "Search Display Controller" shows up and let you search... But now I need to remove that searchbar and call the "Search Display Controller" from a button.

The problem is that if I remove the SearchBar when I call (from the button):

   [self.searchDisplayController setActive:YES animated:YES]

I can't see the UISearchBar on top of the View.

I have no idea how to fix this... I have already tried:

  • self.tableView.tableHeaderView = nil in the viewDidLoad and when touching the button I set the UISearchBar as the table header again... it looks ugly and the animation is not smooth at all.
  • hide the searchbar and show it when the button is pressed. (i get an empty space in the tableview's header) and the animation is really bad, because the UISearchBar gets first displayed in the header and the it's moved up to the top of the view...

Any help will be more than welcome!! Thanks!

Was it helpful?

Solution

I realise that you have tried that, but thats the way we do it and it works:

We add the UISearchBar into the view (not the table view). That being said you can't do that if you are using a UITableViewController. You have to add the tableView to a UIViewController. Then we link it via an Outlet to the Controller and then set it to hidden in viewDidLoad:

self.searchBar.hidden = YES;

Then create a selector to show the searchBar again:

- (IBAction)search:(id)sender
{
  self.searchBar.hidden = NO;

  [self.searchBar becomeFirstResponder];

  [self.searchDisplayController setActive:YES animated:YES];
}

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top