I have a UIViewController with a standard UITableView and Search bar with Search delegate added. The view has a segmented control in the navigation bar, when the user changes the segmented control I would like to hide the searchBar.
The code I am using is:
- (void)segChange {
if ([segmentedControl selectedSegmentIndex] == 0) {
[[[self searchDisplayController] searchBar] setHidden:YES];
// This does not work:
[[[self searchDisplayController] searchResultsTableView] setContentOffset:CGPointZero animated:NO];
}
else {
[[[self searchDisplayController] searchBar] setHidden:NO];
}
}
The code hides the searchBar fine, but it also leaves a nasty white space at the top of the table view.... any ideas on how to get rid of it???
Thanks
This code solved the problem:
- (void)segChange {
if ([segmentedControl selectedSegmentIndex] == 0) {
[self.myTableView setTableHeaderView:nil];
}
else {
[self.myTableView setTableHeaderView:[[self searchDisplayController] searchBar]];
}
}