How to hide the UISearchDisplayController's search bar

1.4k views Asked by At

I'm using a UISearchDisplayController.

When a user select a row in the table, I want to hide the search bar.

Here's my try:

    

- (void)displaySearchBar:(BOOL)show {
    [UIView animateWithDuration:0.15
                          delay:0
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{

         [m_searchDisplayController.searchBar setHidden:!show];
         [m_categoriesView.categoriesTable setContentInset:show ?
         UIEdgeInsetsMake(0,0,0,0) : UIEdgeInsetsMake(-CGRectGetHeight(m_searchDisplayController.searchBar.frame),0,0,0)];

         if( show ) {
             [m_categoriesView.categoriesTable setContentOffset:CGPointZero];
         }

    }
    completion:NULL];
}

All works fine except when the user rotate the device. The search bar is hidden but I got a black space in top of the table.

Someone have a clue ?

Best regards,

Martin

2

There are 2 answers

0
Gabriel On

why don't you use

[self.searchDisplayController setActive:NO animated:YES];

instead of all that code. this will remove the keyboard as well

1
sosborn On

I am going to guess that your tableview isn't properly resizing so when the searchbar is removed you see whatever the background is of the parent view.