Вы можете изменить значение массива в switchChange
action
позволяет мне взять массив для переключения, как показано ниже:
var arrSwitch = [false,false,false,false,false,false,false,false,false,false]
Ниже мой cellForRowAt
метод
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! customCell
cell. switchView.setOn(self.arrSwitch[indexPath.row], animated: false)
cell. switchView.tag = indexPath.row
cell. switchView.addTarget(self, action: #selector(self.onSwitchTap(_:)), for: .valueChanged)
return cell
}
Вот мое onSwitchTap
Действие
@IBAction func onSwitchTap(_ sender: UISwitch) {
self.arrSwitch[sender.tag] = !self.arrSwitch[sender.tag]
}
Теперь на свитке сохранятся последние сделанные вами изменения.