In the coding the below checks if the condition is true
, shows a check mark in cell
it, if not, shows nothing. How can I make it so that the user can deselect the cell
by clicking on the device?
// Boolean Array
var esVisitado = [Bool] (count: 21, repeatedValues: false)
if Visitado[indexPath.row] {
cell.accessoryType = .Checkmark
} else {
cell.accessoryType = .None
}
return cell
let esVisitadoAction = UIAlertAction(title: "Que quieres decir?", style: .Default, handler: { (action:UIAlertAction!) -> Void in
let cell = tableView.cellForRowAtIndexPath(indexPath)
cell?.accessoryType = .Checkmark
self.Visitado[indexPath.row] = true
})
optionMenu.addAction(esVisitadoAction)
tableView.deselectRowAtIndexPath(indexPath, animated: false)
After an hour trying to fix this problem I was finally able to solve my problem, which I had to be:
Now when you select something it asks you
Seleccionar
and if you wantdeseleccionar
you have to tap again and selectDeseleccionar
. I still haven't been able to find a way to be able to deselect, when the user taps on the device 2 times.Here's how you could do it by following best practices like creating a model for the data you put in the
TableView
:In this case it
MyObject
would represent each data you want to put in theTableView
. I have only defined a title and its status, to know if it is selected or not. It is fully functional.Making it modular allows you to better organize your code and make it more readable. Whenever possible, use this type of pattern when creating your applications.
Here is the code for one tap and two taps. What you have to do is tell it how many times it is necessary to press with
numberOfTapsRequired