繁体   English   中英

从不从UITableViewCell调用prepareForSegue

[英]prepareForSegue Never Called from UITableViewCell

我的代码中有一个有趣的错误,该错误使得选择UITableViewCell来触发segue(一个50抽头的过程)。 此外,仅当这些触摸同时向下拖动时,才倾向于选择!

我已删除了单元格中的所有内容,以消除此行为是由于内容遮盖了选择区域而导致的。

我觉得根本原因是情节提要问题而不是代码问题,因为我看不到有什么代码可以触发此行为。

我希望就解决此问题的步骤有任何见识。

将断点添加到prepareForSegue通知我,尽管使用了适当的Identifier ,但该方法从未得到调用。 我还测试了从ViewControllerUITableViewCell本身发起的segues,但无济于事。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "productDetailSegue" {
        if let destination = segue.destinationViewController as? ProductDetailVC {
            if let productIndex = tableView.indexPathForSelectedRow?.row {
                destination.productArray.append(tableView.productList[productIndex])
            }
        }
    }
}

自定义UITableView类:

class ProductTableView: UITableView, UITableViewDataSource, UITableViewDelegate {

    var productList = [Product]()

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return productList.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let product = self.productList[indexPath.row]
        let cell = tableView.dequeueReusableCellWithIdentifier("ProductCell") as? ProductCell

        cell.picRequest?.cancel()
        cell.configureCell(product)

        return cell
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM