2

I would like to show a search bar when the user clicks on a search button. I have found that a lot of people use an offset to hide the search bar on launch. However, is there a way to really hide it, something like a .hidden property?

This is the offset approach but the search bar is still there just offset out of view temporarily. I would like it to really disappear unless needed.

I guess the other approach is to create a new view controller and launch that when the search button is clicked but that is additional overhead..especially as I have a number of these tableviews. Thx for any ideas.

in ViewDidLoad:
 UISearchBar *searchBar;
    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 70, 320, 44)];
    searchBar.showsCancelButton = YES;
    searchBar.delegate = self;
    self.tableView.tableHeaderView = searchBar;



In viewWillAppear:

[self.tableView setContentOffset:CGPointMake(0.0, self.tableView.tableHeaderView.frame.size.height) animated:YES];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user1904273
  • 4,562
  • 11
  • 45
  • 96

1 Answers1

2

You can use the hidden property
To hide the search bar use

searchBar.hidden = true

To unhide is just set it to false!
Hope this helps

votelessbubble
  • 788
  • 6
  • 19