I'm using a static table view which contains 3 different cells. And when a button in the first cell is tapped, the height of the first cell should increase. Below is the function called when the button is tapped.
@IBAction func toggleExpandCamera(_ sender: Any) {
self.shouldShowCameraPreview = !self.shouldShowCameraPreview
self.tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
}
And in the table view's delegate heightForRowAt()
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
let expandedHeight: CGFloat = 415
let collapsedHeight: CGFloat = 115
if self.shouldShowCameraPreview {
return expandedHeight
}
return collapsedHeight
} else if indexPath.row == 2 {
// If already premium, dont show purchases cell.
if AGTUserDefaultValues.isUserPremium {
return 0
}
// Last cell should be same height as the table view
return self.tableView.frame.height - (self.navigationController?.navigationBar.frame.height ?? 0)
- min(UIApplication.shared.statusBarFrame.height, UIApplication.shared.statusBarFrame.width)
} else {
return super.tableView(tableView, heightForRowAt: indexPath)
}
}
I've verified that heightForRowAt()
IS getting called, and it is working fine for the other cell heights when toggleExpandCamera()
is called. It's just that the first cell that is behaving quite weird. It seems like it disappeared or something. I've attached screenshots down below, before and after expanding.
On further inspection, it looks like the cell still exist, but still has the same height. The only difference is there's now more space between the two cells. I also found out the alpha value of the cell is 0.
UPDATE I've tried created a new project, with only the tableview and the function to expand the cell, and still on that project, the same thing happened. If anyone is curious to help I've uploaded the project here.