When selecting and deselecting a record found in a tableView cell I have a checkmark accessory appear.
I am doing so as the following:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectRow()
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
}
The issue is it always takes two taps to deselect the checkmark if the record already exists when the tableView is first loaded.
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
unselectRow()
tableView.cellForRow(at: indexPath)?.accessoryType = .none
}
The tableView is based on JSON with the following structure:
var structure = [JSONStructure]()
struct JSONStructure: Codable {
var peron: String
var update: Int
}
If update
is has a value of 100 a checkmark is applied if the value is a 200 no checkmark is applied.
This is done in cellForRowAt
as the following:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let TableInfo: JSONStructure
if (TableInfo.update == 100) {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
}
When the tableView first loads and a checkmark already exist because the update
criteria is met, how can I prevent having to double press to unselect the record?