0

I am creating something similar to alarm app. Like alarm app on selected days. Is there any method or delegate function of the table to help me disable all other cells if every day is selected. And if every day is selected all other days are already selected and the only way to change it by unticking every day.

Please help if there is some easy way or lib. Otherwise, I guess it gonna take a long time and will need to reload table every time user select every day to make changes.

My code so far

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

    if let cell = tableView.cellForRow(at: indexPath) {

        if cell.accessoryType == .checkmark {
            cell.accessoryType = .none
            if indexPath.row == 0 {
                cell.isUserInteractionEnabled =  true
            }
            removeDays(n: UInt8(indexPath.row))

        } else{
            cell.accessoryType = .checkmark
            if indexPath.row == 0 {
                cell.isUserInteractionEnabled =  false
            }
            addDays(n: UInt8(indexPath.row))
        }
    }
}
cole
  • 3,147
  • 3
  • 15
  • 28
  • pls add your done code. – dahiya_boy Aug 21 '17 at 09:57
  • 2
    Add a `selected` property to your model, enable/disable the cell in `cellForRow` accordingly. To deselect all modify the **model** by calling `dataSource.forEach{ $0.selected = false }` and reload the table **view**. – vadian Aug 21 '17 at 10:01
  • 1
    Possible duplicate of [UItableviewCell Deselect all](https://stackoverflow.com/questions/38430668/uitableviewcell-deselect-all) – MGY Aug 21 '17 at 10:13
  • Thanks for your help !! But I found another way of solving my problem. – cole Aug 21 '17 at 11:46

0 Answers0