繁体   English   中英

自定义ios tableview单元不起作用

[英]custom ios tableview cell not working

我有一个自定义的tableview单元格,如果单击该单元格,则应将其展开,如果未单击,则该单元格不应被展开。

还有一个自定义视图,如果单击该单元格,我希望增加该自定义视图的高度,如果未单击该单元格,则它应该是某个高度。下面的代码在cellForRowAt中设置

 if TableView.rowHeight == 126 {

            cell.CustomView = UIView(frame: CGRect(x: 7, y: 8, width: 359, height: 20))

            return cell
        }
        else{

        }

但是我设置的更改视图高度的代码不起作用,并且我不确定从那里去哪里

当未单击该单元格时,这就是我的自定义视图的外观: 在此处输入图片说明

单击单元格时,自定义视图如下所示: 在此处输入图片说明

如您所见,我的问题是未单击该单元格时,视图的底部是一条直线,但是当单击该单元格时,底部是圆形的。 我希望在未单击单元格时也对视图进行四舍五入。

调用beginUpdatesendUpdates以强制tableView更新高度

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // new row selected
    self.selectedIndex = indexPath
    tableView.beginUpdates()
    tableView.endUpdates()
}

也可以看看

在下面添加代码。 希望这对你有帮助。

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()
    }

礼貌:@JožeWs

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM