【发布时间】:2018-03-23 09:49:28
【问题描述】:
如何单击 tableView 行将行上的开关变为绿色,然后当我单击下一行时,我想关闭最后一个开关并打开我单击的行上的开关?这是我到目前为止测试过的......
//the switch variable is located in a custom cell
var answerSwitch = UISwitch()
var previousSwitch = Bool()
var rowNumber = Int()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(indexPath.row == rowNumber && cell.answerSwitch == false) {
cell.answerSwitch = true
} else if(indexPath.row == rowNumber && cell.answerSwitch == true) {
cell.answerSwitch = false
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(previousSwitch == false) {
rowNumber = indexPath.row
tableView.reloadData()
previousSwitch = true
} else if(previousSwitch == true) {
tableView.reloadData
previousSwitch = false
}
}
【问题讨论】:
标签: ios swift uitableview uiswitch