Essentially I would like to be able to select all and deselect all cells in a tableview.
Currently I am using:
for section in 0..<tableView.numberOfSections {
for row in 0..<tableView.numberOfRows(inSection: section) {
let indexPath = IndexPath(row: row, section: section)
_ = tableView.delegate?.tableView?(tableView, willSelectRowAt: indexPath)
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
tableView.delegate?.tableView?(tableView, didSelectRowAt: indexPath)
}
}
While this function does work it acts as both a select and deselect all, which is not what is needed. Instead I need it to allways select all records and if some records are already selected they should be ignored when this function is executed. It should only select those records not already selected. How can the function above be modified to only select rows not deselect ones that are already selected.
UPDATE:
I do the following in didSelectRow:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
structure[indexPath.row].isSelected.toggle()
let portfolio = structure[indexPath.row]
updateSelection(of: portfolio, at: indexPath)
}
The function updateSelection is just a function that updates the API using Alamofire,