I'm having a problem with my tableview, I can tap on my cells just fine. But if I quickly tap the same cell twice. It runs the "didSelectRowAtIndexPath" twice. Adding 2 of the same views, to my navigation Controller Stack
Here's the function:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var VC = detaiLSuggestion_VC()
self.navigationController?.pushViewController(VC, animated: true)
var selectedCell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
if selectedCell.backgroundColor == UIColor.formulaFormColor() {
println("Buy Action")
selectedCell.backgroundColor = UIColor.formulaMediumBlue()
UIView.animateWithDuration(0.5, animations: {
selectedCell.backgroundColor = UIColor.formulaFormColor()
})
} else {
println("Sell Action")
selectedCell.backgroundColor = UIColor.formulaGreenColor()
UIView.animateWithDuration(0.5, animations: {
selectedCell.backgroundColor = UIColor.formulaLightGreenColor()
})
}
why am I able to select the same cell twice? and how would I go about fixing that?
why am I able to select the same cell twice?
Because the cell is still on screen to be tapped. You might want to do something other than navigation with cell taps and then you would not want to block future taps. Also multiselect would be much more complicated if this was not the case.
and how would I go about fixing that?
A simple boolean flag to indicate that something has been tapped would work or else you might want to set the allowsSelection property of the CollectionView to NO while you are presenting another view controller