自定义部分宽度错误 header 形成 xib

Wrong width of custom section header form xib

我无法使视图的宽度适应 table 视图在不同屏幕尺寸上的大小

这是我在 viewDidLoad() 上的代码

    view.tableView.registerNib(UINib(nibName: "Header", bundle: NSBundle.mainBundle()), forHeaderFooterViewReuseIdentifier: "Header")

在 Table 视图代理上:

  func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    var cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("Header") as! Header
    // etc 
 }

请记住,我不想将其放入情节提要中并且我正在使用自动布局。

有什么建议吗?

我的 xib 由一个 UITableViewCell 组成。我用 UIView 替换了它,它解决了我的问题