Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift ios 11中的Tableview标题视图问题_Swift_Tableview_Ios11 - Fatal编程技术网

Swift ios 11中的Tableview标题视图问题

Swift ios 11中的Tableview标题视图问题,swift,tableview,ios11,Swift,Tableview,Ios11,我在viewForHeaderInSection函数中面临一个问题。在ios 10中工作正常,但在ios 11中,每次重新加载tableview时都会创建重复视图,这意味着dequeueReusableHeaderFooterView无法工作 我遵循添加viewForHeaderInSection的过程。 首先,我为自定义标题视图注册nib,该视图是UITableViewHeaderFooterView的子类 self.tblView.register(UINib(nibName: "Comm

我在viewForHeaderInSection函数中面临一个问题。在ios 10中工作正常,但在ios 11中,每次重新加载tableview时都会创建重复视图,这意味着dequeueReusableHeaderFooterView无法工作

我遵循添加viewForHeaderInSection的过程。 首先,我为自定义标题视图注册nib,该视图是UITableViewHeaderFooterView的子类

 self.tblView.register(UINib(nibName: "CommentShotringHeader", bundle: nil), forHeaderFooterViewReuseIdentifier: "CommentShotringHeader")
下面是我的UITableViewDelegate方法

 func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 45.0
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let viewHeader = self.tblView.dequeueReusableHeaderFooterView(withIdentifier: "CommentShotringHeader") as! CommentShotringHeader
    return viewHeader
}
这就像IOS 11中的问题,或者这个方法中的任何更改,我已经搜索过了,但仍然没有得到正确的解决方案

如果有人也面临同样的问题。找到了解决办法。请推荐我


提前感谢。

不要在iOS11上使用
estimatedSectionHeaderHeight
(在11.3之前测试)。它可能导致多个问题,其中一个问题就是你所解释的

如果可以预先计算高度,请使用

self.tableView.sectionheaderh8=40

而不是

self.tableView.estimatedSectionHeaderHeight=40

否则重写委托方法:

// Swift
public override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    // return calculated height
}

// Obj-c
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    // return calculated height
}

同样的问题。你找到原因了吗?没有,我没有得到Hanks的回复@mojtaba你能解释一下为什么在新的ios版本中会发生这种情况吗。因为如果我想用autolayout设置标题的动态高度,我该如何实现。@Rakesh我已经向苹果报告过了,总有一天它会被修复的。我们无法使用自动布局。@Rakesh如果问题解决了,请将问题标记为已回答