I have searched and haven't seen a solution to:
- I have a tableView that allows multiple selections
- I want to have a button to allow those selections to all be cleared at the same time, in Swift. The button will be on a different viewController (a
UIViewController
) than the TableView. Is it ok to use protocol & delegate, or is singleton required? I want it to update when the button is clicked.
I saw an answer from Dejan Skledar a few years ago here: UITableViewCell checkmark to be toggled on and off when tapped and the function called resetChecks()
seems what I was looking for, but I am having trouble getting what I wrote for Swift to work. When I run it, it doesn't actually go into the method, and then when the method is called, it crashes with "unexpectedly finding nil". Please, can anyone offer some advice? Thanks. Here is what I wrote:
func removeChecks() {
for i in 0...grainTableView.numberOfSections - 1 {
for j in 0...grainTableView.numberOfRows(inSection: i) - 1 {
if let cell = tableView(grainTableView, cellForRowAt: [i,j]) as? UITableViewCell {
cell.accessoryType == .none
}
}
}
}