I have a custom tableview cell, if the cell is clicked then the cell should be expanded and if not clicked then the cell should not be expanded.
There is also a custom view and if the cell is clicked, I want the height of the custom view to be increased and if the cell is not clicked then it should be a certain height.Below this code is set in cellForRowAt
if TableView.rowHeight == 126 {
cell.CustomView = UIView(frame: CGRect(x: 7, y: 8, width: 359, height: 20))
return cell
}
else{
}
But the code I set to change the height of the view is not working and I am not sure where to go from there
When the cell is not clicked this is how my custom View looks like:
When the cell is clicked this is what the custom view looks like:
As you can see my problem is when the cell is not clicked, the bottom of the View is a straight line but when the cell is clicked, the bottom is rounded. I want the View to also be rounded when the cell is not clicked.
Call beginUpdates
and endUpdates
to force tableView
to update heights
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// new row selected
self.selectedIndex = indexPath
tableView.beginUpdates()
tableView.endUpdates()
}
Add the code below . Hope this is gonna help you .
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//performSegue(withIdentifier: "toDetail", sender: self)
self.isExpanded = true
self.selectedIndex = indexPath
tableView.beginUpdates()
tableView.endUpdates()
self.isExpanded = false
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
self.selectedIndex = IndexPath()
tableView.beginUpdates()
tableView.endUpdates()
}
Courtesy : @Jože Ws
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.