UITableViewDelegate methods not called after Swift 3.0 and Xcode 8 migration

前端 未结 3 1061
予麋鹿
予麋鹿 2021-01-19 09:10

After migrating my codebase from Swift 2.2 to Swift 3.0, I noticed that my UITableView footer did not show up. It turns out that none of my UITableViewDe

3条回答
  •  深忆病人
    2021-01-19 09:46

    In Xcode8, or latest Swift version, the method signature has been changed. This change might be causing your code to not call delegate method.

    Fix it by writing method again using autocomplete.

    Old Method -

    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat? {
        return 50.0
    }
    

    New Method -

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

    heightForHeaderInSection has to be used while using viewForHeaderInSection.

    Hope this helped.

提交回复
热议问题