2017-03-17 43 views
0

有一些问题,我不明白。我在xib文件中有单个静态单元,我想从那个单元的细节披露附件中继续到其他视图控制器。如何从xib文件详细披露静态单元格创建segue

猜猜,我要使用这个方法:

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

但我有一个错误:

Could not cast value of type 'Lists.ListViewController' (0x104c0e7b8) to 'UITableViewCell' (0x106875bf8).

我怎样才能正确地创建这个SEGUE?

+0

为什么你想让发件人成为**披露按钮类**? –

+0

@NiravD就是这样的例子。我刚刚编辑过问题。 –

+0

你在哪里得到这些错误? –

回答

2

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

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

现在访问该索引路径prepareForSegue

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 
     } 
    } 
} 
+0

永远不知道发件人可能是indexPath ...谢谢! –

+0

@ wm.p1us欢迎队友:) –

相关问题