4

How can I hide UISearchDisplayController of UITableView initially ? I just want user to scroll up to see the UISearchBar.

UPDATE: I am thinking of scrolling the UITableView 40px lower, so that the UISearchBar can be "hidden" from user.

Lebyrt
  • 1,398
  • 1
  • 9
  • 18
Raptor
  • 51,208
  • 43
  • 217
  • 353

2 Answers2

7

My solution is in viewWillAppear:animted :

[my_table_view setContentOffset:CGPointMake(0, searchController.searchBar.bounds.size.height)]; 

UPDATE we should obtain the height of UISearchBar instead of using fixed values.

Raptor
  • 51,208
  • 43
  • 217
  • 353
1

Here is how I hide search bar in view will appear. This snipped will make sure that search bar is initially hidden only at the very first time of view will appear call.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    //hide search bar
    if (_searchBarRevealed == NO) {
        self.tableView.contentOffset = CGPointMake(0, 44);
        _searchBarRevealed = YES;
    }
}
Peter Stajger
  • 1,625
  • 17
  • 25