【问题标题】:The method selectRow(at:animated:scrollPosition:) doesn't call tableView(_:didSelectRowAt:)方法 selectRow(at:animated:scrollPosition:) 不调用 tableView(_:didSelectRowAt:)
【发布时间】:2017-03-02 09:27:30
【问题描述】:

我想通过selectRow(at:animated:scrollPosition:) 设置默认选中行。但是文档说调用这个方法不会导致代理收到tableView(_:didSelectRowAt:) 消息。

如何设置默认选中行并调用tableView(_:didSelectRowAt:)

【问题讨论】:

标签: ios swift uitableview


【解决方案1】:

您可以拨打tableView(_:didSelectRowAt:)

selectRow(at:animated:scrollPosition:)之后

【讨论】:

    【解决方案2】:

    我只需要以编程方式调用tableView(_:didSelectRowAt:)

    【讨论】:

      【解决方案3】:

      这对你有用。

      tableView.delegate = self
      

      在 viewWillAppear() 或 viewDidLoad 几毫秒后,调用:

      tableView.selectRow(at: <IndexPath?>, animated: <Bool>, scrollPosition: <UITableViewScrollPosition>)
      

      在这里分享你完整的源代码,这样可以给你更好的建议。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-30
        相关资源
        最近更新 更多