【问题标题】:Cell Tap Doesn't Work on didSelectRowAtIndexPath单元格点击在 didSelectRowAtIndexPath 上不起作用
【发布时间】:2015-11-10 14:02:13
【问题描述】:

我正在使用 Parse.com 构建我的应用程序。

我将PFQueryTableViewController 初始化为我的子类。

我无法点击 indexPath.row 以使单元格指向另一个 viewController 并传递数据。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

       print("tapped")
        //Nothing prints. The simulator cell doesn't even change color as it normally does... 

}

在没有 Parse 的普通项目中,我点击它,它会将我引导到我希望它引导的位置。我不明白为什么这在这里不起作用。

我参考了几个链接,比如:

  1. https://www.parse.com/questions/pfquerytableview-didselect-row-open-pbobject-in-uiwebview(过时且客观-c)
  2. https://www.parse.com/questions/using-pfquerytableviewcontroller-in-detail-view(没用)
  3. didSelectRowAtIndexPath method at PFQueryTableViewController(也没有用)

没有任何帮助。

我还尝试在自定义单元格的视图上使用 UIGestureecognizer。这也无济于事......

这是属性检查器:

http://postimg.org/image/3omx3serh/

我已选择和取消选择相关部分。没有任何效果。

编辑:我也在使用初始化器:

 override init(style: UITableViewStyle, className: String!)
    {
        super.init(style: style, className: className)

        self.pullToRefreshEnabled = true
        self.paginationEnabled = false
        self.objectsPerPage = 25

        self.parseClassName = className
        self.tableView.rowHeight = 120
        self.tableView.allowsSelection = false
    }

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

知道为什么我不能点击单元格吗?关于如何点击单元格的任何想法?

【问题讨论】:

  • 您是否有一个 uibutton 或其他可以接收点击而不传递到您的单元格的东西?
  • 应该是单元格本身。 didSelectRowAtIndexPath 应该触发到另一个 viewController 的 segue。甚至被认为存在一个细胞。 cellForRowAtIndexPath 有效,它在 UI 上打印不同的标签和按钮。但我希望细胞本身能够捕捉到触摸。

标签: swift parse-platform swift2 didselectrowatindexpath parseui


【解决方案1】:

首先,我会检查您的表视图是否在属性检查器中启用了“启用用户交互”。

其次,我将检查在您的视图控制器的身份检查器中插入了哪个类。

【讨论】:

  • 我在 XIB 文件中创建单元格。该单元格是正确的类,它是我在PFQueryTableViewController 中引用的类。检查我的更新答案
【解决方案2】:

我还在使用我正在访问的初始化程序。这个 PFTableViewController 我只在代码中构建。对于那些在代码中而不是在故事板中构建的人,请确保self.tableView.allowsSelection = true。看到其他链接遇到类似问题。这里是初始化器的完整代码:

override init(style: UITableViewStyle, className: String!)
{
    super.init(style: style, className: className)

    self.pullToRefreshEnabled = true
    self.paginationEnabled = false
    self.objectsPerPage = 25

    self.parseClassName = className
    self.tableView.rowHeight = 120
    self.tableView.allowsSelection = true
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

意识到self.tableView.allowsSelection = false 被设置为 false 而不是 true。

我将它设置为 true,现在它可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-19
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    相关资源
    最近更新 更多