【问题标题】:Header view is not display after search iOS8 + XCode6搜索 iOS 8 + XCode 6 后不显示标题视图
【发布时间】:2014-09-03 14:33:15
【问题描述】:

我有适用于 iOS7 及以下版本的工作应用程序
我使用 UISearchDisplayController 在表格中进行搜索。

问题:
iOS8 中不显示搜索头后视图。
如下图所示。

搜索前:

搜索后:


我尝试使用 UISearchController 但也有同样的问题 我使用此代码link

我在 TPSMastreViewController.m 中添加以下代码

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *v = [[UIView alloc] init];
    v.backgroundColor = [UIColor greenColor];
    return v;
}


我检查了那个委托 - (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
在 iOS8 的情况下不调用。
编辑:
我的理解是只有 UITableViewDataSource 委托被调用, UITableViewDelegate 没有。
请不要我在 ViewDidLoad 中设置了两个委托
问题:
1] 是 UI 变化吗?
2]任何人都有补丁,以便委托方法将强制调用。

【问题讨论】:

    标签: ios8 xcode6 uisearchdisplaycontroller uisearchcontroller


    【解决方案1】:

    我找到了答案,所以写在这里可能会帮助其他面临同样问题的人

    只需添加委托 heightForHeaderInSection,它将显示 UISearchController(iOS8) 的 searchResultsController 和 UISearchDisplayController(iOS7) 的 searchResultsTableView 的标题视图

    在 TPSMastreViewController.m 中添加以下代码即可解决问题。

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 20;
    }
    

    我通过阅读这个问题找到了答案 :)
    in iOS 8 UITableView heightForHeaderInSection is not optional

    【讨论】:

    • 如果您的标题高度始终为 20,则无需实现委托方法,只需设置 UITableView 的 sectionHeaderHeight 属性即可。如果您说 1000 个部分,那么与调用委托方法 1000 次相比,表格将高度乘以 1000 得到总高度会更快。
    • 感谢您的建议,但我的问题是委托方法 viewForHeaderInSection 没有被调用,在搜索和实现这个 viewForHeaderInSection 之后,它被调用了。
    • 试试这个,它也可以工作(并且表现更好)[self.tableView setSectionHeaderHeight:20];
    • 不错的发现。也遇到过这个问题。
    猜你喜欢
    • 1970-01-01
    • 2014-11-29
    • 2015-01-20
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 2015-07-07
    • 2019-11-03
    • 1970-01-01
    相关资源
    最近更新 更多