2017-07-15 88 views
0

我有4個單元格,每個單元格中都有一個標籤。使用條件執行segue併發送數據如果條件

enter image description here

每當用戶點擊一個單元格,將帶他們到一個不同的看法,並在該視圖我有一個頂部標籤應命名爲喜歡的單元格標籤。所以,如果我點擊細胞001那麼接下來的頁面標題標籤應該低於001圖片顯示標題標籤:但是

enter image description here

我用SEGUE準備通過標題標籤的價值,我怎麼能寫代碼,說:

if cell label = 001 { 
    newViewTitle.text = cell label 
} 

這是我目前的代碼賽格瑞準備:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

    if let destination = segue.destination as? VolumeImgVC { 


     if let VolumeNumLbl = volumEDnum as? String! { 
      destination.Vtitle = VolumeNumLbl 
     } 
     if let VolumeNumLbl = volumEDnum1 as? String! { 
      destination.Vtitle = VolumeNumLbl 
     } 
     if let VolumeNumLbl = volumEDnum2 as? String! { 
      destination.Vtitle = VolumeNumLbl 
     } 

    } 
} 

上面的代碼不工作,ONL y執行最後一個let語句。

有什麼建議嗎?謝謝

+0

你想當前單元格的數據傳遞到一個視圖控制器? –

回答

1

細胞的點擊創建cellnamelabel數組的數組只需使用tableView.indexPathForSelectedRow屬性來獲取選定indexPath並將數據傳遞

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     if segue.identifier == "detailSeque" { 
      if let destination = segue.destination as? VolumeImgVC { 
      if let indexPath = self.tableView.indexPathForSelectedRow { 
       let volumeNum = volumeNumLblArray[indexPath.row] 
       destination.Vtitle = volumeNum 
      } 
      } 
     } 
    } 
+0

你是什麼意思通過單擊單元格創建單元格名稱標籤數組?如何以及在哪裏做到這一點? @suhit –

+0

請參考http://www.codingexplorer.com/segue-uitableviewcell-taps-swift/ – suhit