问题描述
我已经在相当标准的 tableview(表格 + 搜索的相同数据源)上实现了 UISearchDisplayController.我遇到的问题是,当结果没有填满屏幕时,实际结果下方会出现伪"行.
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.
我能够设置背景颜色,但找不到抑制这些行/分隔符的好方法.它们似乎与我的 numberOfRowsInSection:委托响应分离.
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.
如果我设置 searchResultsTableView.separatorColor(绿色),它只会改变实际的结果行.
If I set the searchResultsTableView.separatorColor (green) it only changes the actual results rows.
我能够将 separatorStyle 更改为 UITableViewCellSeparatorNone,但随后我必须在实际结果上手动重新创建分隔符,并且存在边缘情况(例如选择颜色覆盖了我的视图).
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?
推荐答案
你或许可以为 Search Display Controller 实现这个委托方法:
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];
}
这将使最后几行消失.您当然可以使用您选择的任何其他方法来执行此操作.例如,如果您想在普通 UITableView 上获得相同的效果,您可以在 UIViewController 的 viewDidLoad
中执行此操作.
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.
这篇关于停止 UISearchDisplayController 显示空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!