开发者

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 use开发者_JAVA百科r 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]];
    }
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜