ios - swift didSelectRowAtIndexPath 可以多次调用

标签 ios uitableview swift didselectrowatindexpath tableviewcell

我的 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/

相关文章:

ios - dispatch_io_read 如果接收数据大小小于长度,套接字将等待更多数据

ios - 如何使固定内容超出 iOS 键盘?

ios - 调度队列上的 TableView 单元格中填充了错误的数据

iphone - 使用 cellForRowAtIndexPath : method 修改现有的可重用单元格

swift - PDF 文件未在 iPad webView 中显示

ios - 未调用 UICollectionView 的 didSelectItemAtIndexPath

Swift - 可变丢失数据

ios - 解包可选值时意外发现 nil [swift 3.0]

ios - 无法使用 twitter fabric iOS 框架从 twitter 获取用户的电子邮件

ios - Swift 中 NSLayoutConstraints 的奇怪行为