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,376
  • 1
  • 9
  • 18
Raptor
  • 53,206
  • 45
  • 230
  • 366

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
  • 53,206
  • 45
  • 230
  • 366
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;
    }
}
Tankista
  • 1,685
  • 17
  • 26