【问题标题】:Touch Event not triggering on UITableView触摸事件未在 UITableView 上触发
【发布时间】:2017-01-07 21:53:39
【问题描述】:

所以,我的主 UIViewController 中有 3 个不同的 UITableView,我使用 SWITCH 控制内容,评估它在“cellForRowAt”中的哪个表视图,但 3 个表中只有 2 个触发了“didSelectRowAt indexPath”事件。

   func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch tableView {
    case checkoutTable:
        //THIS RIGHT HERE IS NEVER EXECUTED
        if (indexPath as NSIndexPath).row == 0 {
            if self.calculateTotalsInCart() > 0 {
                performSegue(withIdentifier: "sgAddDescount", sender: self)
            }else{

                let alert:UIAlertController = UIAlertController(title: "Descuento Inaplicable", message: "No puedes aplicar descuento a una cuenta en ceros", preferredStyle: UIAlertControllerStyle.alert)
                let okButton:UIAlertAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
                alert.addAction(okButton)
                self.present(alert, animated: true, completion: nil)
            }
        }
        break
    case clientTable:
        if (indexPath as NSIndexPath).row == 0 {
            performSegue(withIdentifier: "clientSelection", sender: self)
        }
        break
    default:
        print("None Selected")
        break;
    }
}

当我点击任何其他 UITableView 时,该方法被调用,但对于这个特定的表,它不是。

我也设置了表的委托和数据源

http://imgur.com/ETP64zA

【问题讨论】:

  • 首先你是否正确设置了checkoutTabledelegate
  • 是的,更新了帖子
  • 表格视图和表格视图单元格的 userIneractionEnabled 是否都设置为 true?
  • 是的,检查过并重新检查过

标签: ios swift uitableview


【解决方案1】:

据我所知,您的代码没有问题,但您可能在某处遗漏了一些我在阅读您的文本时无法弄清楚的东西。这是一种简单的替代方法,它可以帮助您,

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if (tableView.tag == 200) {
        //checkoutTable
    }
    if (tableView.tag == 201) {
        //clientTable
    }
    if (tableView.tag == 202) {
        //your third table
    }
} 

我希望这可以帮助你。

【讨论】:

  • 问题是,点击此特定表时永远不会调用事件
【解决方案2】:

检查属性检查器中的选择是否是单选而不是无选。也只需在 viewDidLoad 中启用 Tableview 的选择

tableView.allowsSelection = true

【讨论】:

    猜你喜欢
    • 2019-05-09
    • 1970-01-01
    • 2011-08-16
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多