【发布时间】:2017-08-24 08:44:11
【问题描述】:
我的表格视图是这样的
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! Cell
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 200
}
我的 tableviewcell 看起来像这样
class Cell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
当我更改任何单元格上的开关状态并滚动时。另一个单元格的开关会在滚动时定期更改其他单元格的状态。请帮忙
【问题讨论】:
-
这是因为单元格出列。你能用数据模型更新你的问题吗?
-
这就是问题所在。我创建了测试项目以查看我的数据模型是否会导致此问题。但是只有这些代码它给了我同样的问题
-
请查看我更新的answer
-
在数据模型中添加一个布尔标志(用于加载单元格数据)并在更新时保存开关状态。在您的 cellForRowAt 方法中,根据布尔标志相应地设置开关状态。
标签: ios swift uitableview uiswitch