R – hide UISearchBar below UINavigationBar after cancelButton was called

cancel-buttoniphoneuisearchbaruisearchdisplaycontroller

I'm typically using [self.tableView setContentOffset:CGPointMake(0,40)]; in order to hide the UISearchBar (that I set as header of the tableView) below the navigationBar. Everything works well in viewDidLoad: the searchBar is below the navigationBar when the view is loaded. Then I put the same line of code

[self.tableView setContentOffset:CGPointMake(0,40)]

in

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller

but it does anything: the searchBar remain visible when cancel Button is clicked.
What's wrong?

Best Answer

The following method should do it:

-(void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{
    [self.tableView setContentOffset:CGPointMake(0,40)];    
}
Related Topic