Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

ios6 - UISearchDisplayController's searchResultsTableView's ContentSize is incorrect. Bug in iOS 7?

The below problem only occurs on an iOS 6.0/6.1 application running on an iOS 7.0+ device.

So I have a UISearchDisplayController that searches our API and returns data. This all works, and everything is displayed as we want. The only problem we are seeing is that after the content has populated the searchResultsTableView, it seems as though when the keyboard is initially hidden, the contentSize of the searchResultsTableView is much larger than the data, and actually seems to be the size of the keyboard. When I enter the search bar, and show the keyboard and hit 'Search' again (just to hide the keyboard), the contentSize then adjusts correctly to only fill the screen, and nothing more. Below is a screen shot of what I am talking about with the initial tableView population.

The white is the table data, and the gray/cream color is the extra tableView space.

Any ideas on how to fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had this exact problem. The solution posted on the developer forums here worked for me. Not sure if it's a bug in iOS 7 or just that they changed the way they're doing things but this is the only solution that I found solved my problem.

Solution from the forum post for the lazy:

- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView {

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];

}



- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];

}



- (void) keyboardWillHide {

    UITableView *tableView = [[self searchDisplayController] searchResultsTableView];

    [tableView setContentInset:UIEdgeInsetsZero];

    [tableView setScrollIndicatorInsets:UIEdgeInsetsZero];

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...