Search code examples
iosuitableviewswift5custom-sections

Table View Height Dynamically


I implemented expandable sections on my UITableView and now my problem is that when the UIViewController loads the table there are rows below the section.

Not expanded:

enter image description here

Expanded:

enter image description here

I want the UITableView to have no rows if the section is not expanded so I can set another UIView below the section. When the section is expanded the UIView should disappear and the table view to be presented on the whole screen.


Solution

  • Simply implement the viewForFooterInSection and return an empty view.

    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView(frame: .zero)
    }