【问题标题】:How to create segue from Detail disclosure of static cell from xib file如何从xib文件中静态单元的详细信息披露中创建segue
【发布时间】:2017-03-17 19:25:01
【问题描述】:

有一些我想不通的问题。我在 xib 文件中有单个静态单元格,我想将该单元格的详细信息披露附件转移到其他视图控制器。

猜猜我必须使用这个方法:

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    self.performSegue(withIdentifier: "SegueID", sender: self) // #ERROR
}

但我有一个错误:

无法转换“Lists.ListViewController”类型的值 (0x104c0e7b8) 到 'UITableViewCell' (0x106875bf8)。

如何正确创建此转场?

【问题讨论】:

  • 为什么要将发件人作为披露按钮类
  • @NiravD 这只是一个例子。我刚刚编辑了问题。
  • 你在哪里得到这些错误?
  • @NiravD 在 self.performSegue 行中..

标签: swift segue


【解决方案1】:

如果你想访问prepareForSegue中的单元格,你可以这样尝试。

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    //Pass the indexPath as sender
    self.performSegue(withIdentifier: "SegueID", sender: indexPath)
}

现在访问prepareForSegue 中的那个indexPath。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "SegueID" {
        let nextVC =  segue.destination as! DestinationVC
        if let indexPath = sender as? IndexPath,
           let cell = self.tableView.cellForRow(at:indexPath) as? CustomCell {
              //access your cell here
        } 
    }
}

【讨论】:

  • 永远不知道发件人可能是 indexPath...谢谢!
  • @wm.p1us 欢迎朋友 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多