tableview单元格中的按钮颜色很快

时间:2016-12-11 12:02:44

标签: ios swift tableview

我正在尝试构建测验应用以及表格视图中显示的问题 每个单元格都有四个按钮(答案)。

问题是,当我点击其中一个按钮时,它也会在其他一些按钮中被选中。

2 个答案:

答案 0 :(得分:0)

由于UITableViewCells正在重复使用,因此每次在cellForRowAtIndexPath方法中将其取列时,都必须“重置”单元格状态。

另一种方法是覆盖UITableViewCell子类中的prepareForReuse方法。

override func prepareForReuse() {
        super.prepareForReuse()
        // Reset the state of cell's properties, e.g. selected state background color
    }

答案 1 :(得分:0)

indexPath.row

中选择时,请确保传递正确的didSelectRowAtIndexPath
相关问题