Table View Height Dynamically

66 Views Asked by At

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.

2

There are 2 best solutions below

0
nico On BEST ANSWER

Simply implement the viewForFooterInSection and return an empty view.

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

just use this code it will remove your unwanted rows.