我正在尝试将一些数据传递到单独的 View Controller ,该 View Controller 连接到导航 Controller ,我可以使用
访问该 View ControllerparentNavigationController!.performSegueWithIdentifier("ExercisePage", 发件人: 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", 发件人: self) }
如果我这样做,它会说没有后续
最佳答案
试试这个:(您不必使用所有 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!
}
}
关于快速将数据从表格 View 单元传递到 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33481882/