I am confused a little bit about settings table view cell accessories.
I have fixed two sections in my table
What I
BlackBerry's answer in Swift 3. UITableView with standard cells, selecting 0 or 1 cells.
private var previousSelection = NSIndexPath()
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let cell = tableView.cellForRow(at: indexPath)!
if cell.accessoryType == .none {
cell.accessoryType = .checkmark
selection = indexPath
if previousSelection == IndexPath() {
previousSelection = indexPath
} else if previousSelection != indexPath {
let previousCell = tableView.cellForRow(at: previousSelection)
previousCell?.accessoryType = .none
previousSelection = indexPath
}
} else if cell.accessoryType == .checkmark {
cell.accessoryType = .none
selection = IndexPath()
}
}