我正在尝试将一些数据传递给单独的视图控制器,视图控制器连接到导航控制器,我可以使用
来访问此视图控制器 parentNavigationController!.performSegueWithIdentifier("ExercisePage", sender: self)
但数据没有传递,这是我的代码?
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell2 = tableView.cellForRowAtIndexPath(indexPath) as! SelectionProperties
let desVc = uploadDetails1()
desVc.workoutName = cell2.nameLabel!
desVc.parentNavigationController!.performSegueWithIdentifier("ExercisePage", sender: self)
}
它表示在打开可选项时发现了nil。
desVc.performSegueWithIdentifier("ExercisePage", sender: self) }
如果我这样做,就说没有赛道
答案 0 :(得分:2)
试试这个:(你不必使用所有if语句......)
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("ExercisePage", sender: indexPath)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
// Get the new view controller using segue.destinationViewController.
if segue.identifier == "ExercisePage"
{
guard let indexPath = sender as? NSIndexPath else {
return }
guard let destinationViewController = segue.destinationViewController as? uploadDetails1 else {
return }
guard let cell = tableView.cellForRowAtIndexPath(indexPath) else {
return }
guard let _ = cell.nameLabel else {
return }
destinationViewController.workoutName = cell.nameLabel!
}
}