Stop UISearchDisplayController from showing empty cells

 ̄綄美尐妖づ 提交于 2019-12-25 04:53:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!