[英]custom ios tableview cell not working
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. 我有一个自定义的tableview单元格,如果单击该单元格,则应将其展开,如果未单击,则该单元格不应被展开。
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 还有一个自定义视图,如果单击该单元格,我希望增加该自定义视图的高度,如果未单击该单元格,则它应该是某个高度。下面的代码在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 调用beginUpdates
和endUpdates
以强制tableView
更新高度
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 礼貌:@JožeWs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.