【发布时间】:2017-10-19 13:24:14
【问题描述】:
我在自定义TableViewCell 中使用我的UISwitch。
UITableViewCell 中的开关将单元格中的项目添加到另一个数组中。但是,我注意到当我更改一个开关时,它也会更改其他单元格中的其他开关。
我认为问题出在 TableView dequeueReusableCell 函数上。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "currencyCell") as? currencyCell else { return UITableViewCell() }
}
【问题讨论】:
-
代码不足以说明问题所在,但我假设您在返回单元格之前没有在
tableView:cellForRowAt:方法中重置UISwitch的值? -
请简要说明您的问题?
-
你好 TawaNicolas,你是对的,我无法重置它。你能告诉我怎么做吗?我可以通过“cell.switchBtn(UISwitch)”访问它。但是,不知道在 (UISwitch) 部分放什么。非常感谢!
标签: ios swift uitableview uiswitch