user1904273
user1904273

Reputation: 4764

Totally hide search bar

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];

Upvotes: 2

Views: 1921

Answers (1)

votelessbubble
votelessbubble

Reputation: 805

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

Upvotes: 2

Related Questions