【发布时间】:2016-09-27 19:48:28
【问题描述】:
我正在尝试在我的应用程序中链接两个视图控制器,但如果不将其附加到我的 tableview 单元格,我无法弄清楚如何链接它们。我希望它只是一个带有标识符的简单 segue,因此我可以使用标识符调用 perfrom segue。但是,我只能通过将它从我的单元格拖动到下一个视图控制器来设法创建一个 segue。
这是我试图链接的两个 VC 的图像,显示了被选中的单元格。
http://imgur.com/gallery/PWJol
我不知道该怎么做。
这是我用于 segue 的代码,似乎是正确的。我希望它在选择一行时进行 segue 并传递所选行的标签名称。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.NameToPass = DietSelectionTableViewCell.TypesOfDiets[indexPath.row]
self.performSegue(withIdentifier: "DietInformation", sender: self)
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "DietInformation" {
if let destinationVC = segue.destination as? DietInformationViewController {
destinationVC.DietTypeLabelText = self.NameToPass
}
}
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
【问题讨论】:
-
在你正在segueing的场景中,按住ctrl并单击顶部的橙色圆圈(代表视图控制器本身)并拖动到你正在segueing的视图控制器。
标签: ios swift uitableview uiviewcontroller segue