tableView.headerView(forSection:0)的高度为nil

时间:2017-07-07 01:42:44

标签: ios swift uitableview uiscrollview

当用户在this tutorial之后滚动时,我正在尝试更改标题视图的高度。但是,当我尝试访问IF(所以我可以更新标题视图的高度)时,值为nil,调试器告诉我“标题视图没有高度”。我使用self.songsTable.headerView(forSection: 0)?.frame.size.heightheightForHeaderInSection以编程方式创建了标题视图。

代码

viewForHeaderInSection

1 个答案:

答案 0 :(得分:0)

您的代码段可能只是缺少这个,但您是否将viewController设置为TableViewDataSource?

class SongsViewController: UIViewController, UITableViewDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()
        songsTable.dataSource = self
    }

    // ... the rest of your code ...
}