There are 5 static cells. When I show all 5 cells, it's fine but If I hide some cell by returning height as zero and the last visible cell is not same as last cell of tableview in storyboard then confusion comes as to how to do that ?
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return hideRow(at: indexPath) ? 0: UITableView.automaticDimension
}
IMO , If last visible row in tableview and lastrow in tableview is same
return indexPath.row == 4 ? 150 : tblHeight - 150
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if hideRow(at: indexPath) {
return 0
}
else {
let tblHeight = infoTable.bounds.size.height
if indexPath.row == 4 {
return tblHeight - yPlusHeightOfPreviousCell
}
return UITableView.automaticDimension
}
}
But the problem now what if 3rd is last row and for 4th and 5th I'm returning 0 as height to hide it.
Then how to make the last visible cell expand and occupy the full space

Add an empty
UIViewas the table footer view:Edit After re-reading your question...
The above code will "hide" the empty rows.
If your goal is to make the "last visible row" fill the remaining height, that will be more considerably complex.
Since your current approach is using a static table view and you won't be doing any scrolling, a much easier approach would be to use a
UIStackViewwith custom views instead of cells. Then everything would be handled by auto-layout, constraints, and the stack view, and you wouldn't need to do any calculating.Edit 2a - move code to a function
Add these vars to your table view controller class:
Add this function:
Call it from
viewDidLayoutSubviews()anytime the table width changes:and change your
heightForRowAtto this:Then, anytime you change the rows (based on user-interaction or whatever), call
reloadDataon the tableView, and then callupdateTable()to re-calculate the last visible row and its height.