Hello!
Having a go at swipe-to-delete functions and the likes in tableView cells today...
When toggling a button I would like it to change colours from green to red and back again. - Any suggestions on how to achieve this?
For the toggle button I have declared a boolean which is set to false at start.
and this is what I've got inside editActionsForRowAtIndexPath:
...
let toggleAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Toggle", handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
let button: UIButton = UIButton()
button.backgroundColor = UIColor.greenColor()
if(self.toggleBool == false) {
self.toggleBool = true
button.backgroundColor = UIColor.redColor()
} else {
self.toggleBool = false
toggleButton.backgroundColor = UIColor.greenColor()
}
self.view.addSubview(button)
})
return [deleteAction, toggleAction]
}
The code snippet above does not make the button change colour when pressed!
Any help in the matter would be much appreciated!