2017-07-15 47 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