问题
I've implemented a UISearchDisplayController on a fairly standard tableview (same datasource for table + search). The problem I am having is when the results don't fill the screen there are "pseudo" rows below the actual results.
I was able to set the background color, but can't find a good way to suppress these rows/separators. They seem decoupled from my numberOfRowsInSection: delegate response.
If I set the searchResultsTableView.separatorColor (green) it only changes the actual results rows.
I was able to change separatorStyle to UITableViewCellSeparatorNone, but then I have to manually recreate the separators on the actual results and there are edge cases (like the selection color covers up my view).
Is there a clean way to hide the rows pointed out in the attached screenshot?
回答1:
You can probably implement this delegate method for the Search Display Controller:
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView;
{
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 1)];
footer.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:footer];
}
This will make those last few rows disappear. You can of course do this in any other method you choose. For example, you can do this in viewDidLoad
of a UIViewController if you want the same effect on a normal UITableView.
来源:https://stackoverflow.com/questions/20434610/stop-uisearchdisplaycontroller-from-showing-empty-cells