UITableView:如何在viewForHeaderInSection中获取heightForHeaderInSection

cho*_*xin 0 objective-c uitableview ios

我正在为我创建自定义节标题视图UITableView.

但是如何在我的viewForHeaderInSection方法中获得tableHeight ?我目前正在执行以下操作并tableHeight保持值0.

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (includeButton)
        return 55;
    else
        return 30;
}

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CGFloat tableHeight = [tableView headerViewForSection:section].frame.size.height;
    ........
}
Run Code Online (Sandbox Code Playgroud)

Leo*_*ica 5

这两种方法都在同一个视图控制器中.只需调用您的实现并传递表视图和部分,如下所示:

CGFloat tableHeight = [self tableView:tableView heightForHeaderInSection:section];
Run Code Online (Sandbox Code Playgroud)