为什么我在Swift的UITableViewHeaderView下得到多余的空格?

时间:2019-05-18 11:32:19

标签: ios swift uitableview

Here is the screenshot: [Screenshot][1]

我已经创建了自己的HeaderView类,并为其设置了tableView默认的HeaderView:

class MyHeaderView: UITableViewHeaderFooterView {
    @IBOutlet weak var countLabel: UILabel!
}

后来我在委托人中使用它:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = tableView.tableHeaderView as! MyHeaderView
    headerView.countLabel.text = "Something here"

    return headerView
}

我还要为其设置高度:

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

但是正如您在图像中看到的那样,HeaderView行下方有额外的空间。当我将heightForHeaderInSection设置为0.0时,一切恢复正常,但是在那种情况下,我的viewForHeaderInSection将不会运行,标签也不会更改。有人可以指出我的错误吗?

更新

我在那里也遇到了这种约束冲突:

"<NSLayoutConstraint:0x600001874cd0 UILabel:0x7fbfeb61cdb0'0 repository results'.height == 24 (active)>", "<NSLayoutConstraint:0x600001876440 V:|-(24)-[UILabel:0x7fbfeb61cdb0'0 repository results'] (active, names: '|':GitHub.SearchHeaderView:0x7fbfeb61c700 )>", "<NSLayoutConstraint:0x6000018764e0 V:[UILabel:0x7fbfeb61cdb0'0 repository results']-(16)-| (active, names: '|':GitHub.SearchHeaderView:0x7fbfeb61c700 )>", "<NSLayoutConstraint:0x600001875040 'UIView-Encapsulated-Layout-Height' GitHub.SearchHeaderView:0x7fbfeb61c700.height == 63 (active)>"

0 个答案:

没有答案