我的 tableview 有问题,我可以很好地点击我的单元格。但是如果我快速点击同一个单元格两次。它运行“didSelectRowAtIndexPath”两次。将 2 个相同的 View 添加到我的导航 Controller 堆栈
函数如下:
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()
})
}
为什么我可以选择同一个单元格两次?我将如何解决这个问题?
最佳答案
为什么我可以选择同一个单元格两次?
因为单元格仍在屏幕上以供点击。你可能想做一些除了使用单元格点击导航之外的事情,然后你不想阻止 future 的点击。如果不是这种情况,多选也会复杂得多。
我该如何解决这个问题?
一个简单的 bool 标志来指示某物已被点击会起作用,否则你可能想要设置 allowsSelection当您呈现另一个 View Controller 时,CollectionView 的属性为 NO
关于ios - swift didSelectRowAtIndexPath 可以多次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29056668/