Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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
Ios tableHeaderView不';无法正确调整大小_Ios_Swift_Uitableview_Cgrectmake - Fatal编程技术网

Ios tableHeaderView不';无法正确调整大小

Ios tableHeaderView不';无法正确调整大小,ios,swift,uitableview,cgrectmake,Ios,Swift,Uitableview,Cgrectmake,我正在将UITableView与自定义tableHeaderView 在我的viewdilayoutsubviews中,我使用的代码如下: let bounds = UIScreen.mainScreen().bounds imageSliderVC.view.frame = CGRectMake(0, 0, bounds.width, bounds.width) layerView.frame = CGRectMake(0, 0, bounds.width, bounds.

我正在将
UITableView
与自定义
tableHeaderView

在我的
viewdilayoutsubviews
中,我使用的代码如下:

 let bounds = UIScreen.mainScreen().bounds

    imageSliderVC.view.frame = CGRectMake(0, 0, bounds.width, bounds.width)
    layerView.frame = CGRectMake(0, 0, bounds.width, bounds.width)

    noButton = constructNopeButton()
    yesButton = constructLikedButton()
    buttonOptionsApply()

    nameLbl.frame = CGRectMake(20, layerView.frame.maxY + 20, bounds.width-40, 20)
    nameLbl.makeNameLabelFormat()
    hashtagLbl.frame = CGRectMake(20, nameLbl.frame.maxY + 5, bounds.width-40, layerView.frame.width/3.66)
    hashtagLbl.makeHashtagFormat()

    seperatorLbl.frame = CGRectMake(20, hashtagLbl.frame.maxY + 15, bounds.width-40, 1)

    groupsLbl.frame = CGRectMake(20, seperatorLbl.frame.maxY + 15, 30, 20)
    groupsLbl.makeNameLabelFormat()
    groupsLbl.sizeToFit()
    groupsCountLbl.frame = CGRectMake(groupsLbl.frame.maxX + 5, seperatorLbl.frame.maxY + 15 , 40, 20)
    groupsCountLbl.sizeToFit()

    headerView.frame = CGRectMake(0, 0, bounds.width, groupsCountLbl.frame.maxY)
    table.tableHeaderView = headerView
没有使用headerView,一切都很好地对齐。 表格与自动布局一起使用-将表格固定到所有边缘

知道为什么会这样吗?试用

        headerView.translatesAutoresizingMaskIntoConstraints = false
它将所有内容与左上边缘对齐

编辑: 视图的设置与在故事板中的设置相同

edit2:屏幕截图

应该是这样的:

 let bounds = UIScreen.mainScreen().bounds

    imageSliderVC.view.frame = CGRectMake(0, 0, bounds.width, bounds.width)
    layerView.frame = CGRectMake(0, 0, bounds.width, bounds.width)

    noButton = constructNopeButton()
    yesButton = constructLikedButton()
    buttonOptionsApply()

    nameLbl.frame = CGRectMake(20, layerView.frame.maxY + 20, bounds.width-40, 20)
    nameLbl.makeNameLabelFormat()
    hashtagLbl.frame = CGRectMake(20, nameLbl.frame.maxY + 5, bounds.width-40, layerView.frame.width/3.66)
    hashtagLbl.makeHashtagFormat()

    seperatorLbl.frame = CGRectMake(20, hashtagLbl.frame.maxY + 15, bounds.width-40, 1)

    groupsLbl.frame = CGRectMake(20, seperatorLbl.frame.maxY + 15, 30, 20)
    groupsLbl.makeNameLabelFormat()
    groupsLbl.sizeToFit()
    groupsCountLbl.frame = CGRectMake(groupsLbl.frame.maxX + 5, seperatorLbl.frame.maxY + 15 , 40, 20)
    groupsCountLbl.sizeToFit()

    headerView.frame = CGRectMake(0, 0, bounds.width, groupsCountLbl.frame.maxY)
    table.tableHeaderView = headerView

这就是它看起来的样子


您可以在UITableViewDelegate方法中设置表格hader视图
表格视图:头部高度部分:
。当然,还可以使用NSLayoutConstraint来定位元素()。

您可以在UITableViewDelegate方法中设置table hader视图
tableView:heightForHeaderInSection:
。当然,还可以使用NSLayoutConstraint定位元素()。

输出是什么?显示屏幕截图。你能发布你的viewForHeaderInSection方法吗?我没有使用这个方法。我来看看。在我的示例中,它应该是什么样子的?好吧,你的问题是关于标题的,我认为你正在子类化一个视图并添加你的自定义行为,但是,也许不是这样,所以你可以发布你的viewController代码来尝试帮助?输出是什么?显示屏幕截图。你能发布你的viewForHeaderInSection方法吗?我没有使用这个方法。我来看看。在我的示例中,它应该是什么样子的?好吧,你的问题是关于标题的,我认为你正在子类化一个视图并添加你的自定义行为,但是,也许不是这样,所以你可以发布你的viewController代码来尝试帮助?