我有 4 个单元格,每个单元格内都有一个标签。
每次用户单击一个单元格时,都会将他们带到不同的 View ,在该 View 中,我有一个顶部标签,其名称应类似于单元格标签。因此,如果我单击单元格 001,那么下一页标题标签应该是 001。下图显示标题标签:
我使用 prepare for segue 来传递标题标签的值,但是,我该如何编写这样的代码:
if cell label = 001 {
newViewTitle.text = cell label
}
这是我当前准备的 segue 代码:
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
}
}
}
上面的代码不起作用,只执行最后一个if let语句。
有什么建议吗?谢谢
最佳答案
在单击单元格时创建一个 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
}
}
}
}
关于ios - 使用 If 条件执行 segue 和发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45114284/