2017-03-17 41 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歡迎隊友:) –

相關問題