KSoza
KSoza

Reputation: 321

Hiding UITableView searchBar leaves a blank space

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

Upvotes: 1

Views: 2423

Answers (2)

KSoza
KSoza

Reputation: 321

This code solved the problem:

- (void)segChange {
    if ([segmentedControl selectedSegmentIndex] == 0) {
        [self.myTableView setTableHeaderView:nil];
    }
    else {
        [self.myTableView setTableHeaderView:[[self searchDisplayController] searchBar]];
    }
}

Upvotes: 6

nicktmro
nicktmro

Reputation: 2288

Rather than hiding the segmented control try setting its frame to CGRectZero

Upvotes: 1

Related Questions