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 UITableViewDelegate
methods get called (ex: func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
).
Interestingly, the UITableViewDataSource
methods are being called and the table is being populated. I have set the parent view controller to be the table's delegate
and dataSource
.
To illustrate the problem, I have created a sample Swift 3.0 project tailored to match my existing codebase as much as possible. Maybe something changed in Swift 3/Xcode 8 that I am not aware of or I might be missing something really obvious. Thank you for your help!
After I checked your sample project:
You didn't did anything wrong, but referring to
viewForFooterInSection
, it will not get called until you implementheightForFooterInSection
method:Similar Cases:
No implementing for
heightForHeaderInSection
==> No calling forviewForHeaderInSection
even if it's implemented.Returning
numberOfRowsInSection
as zero ==> No calling forcellForRowAt
even if it's implemented.Additional Note: you don't have to add
tableView.dataSource = self
andtableView.delegate = self
inviewDidLoad()
, they have been set in the interface Builder.You should set the height of the footer
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 -
New Method -
heightForHeaderInSection has to be used while using viewForHeaderInSection.
Hope this helped.