开发者

Hiding UITableView searchBar leaves a blank space

开发者 https://www.devze.com 2023-01-24 16:17 出处:网络
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 segment

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

精彩评论

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