自定义节标题formsxib的错误宽度

我无法使视图的宽度适应不同屏幕大小的表视图的大小

这是我在viewDidLoad()上的代码

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

并在表视图委托:

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

请记住,我不想把这个在故事板,而我正在使用自动布局。

有小费吗?

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