快速将数据从表格 View 单元传递到 View Controller

标签 swift uitableview segue

我正在尝试将一些数据传递到单独的 View Controller ,该 View Controller 连接到导航 Controller ,我可以使用

访问该 View Controller

parentNavigationController!.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/

相关文章:

ios - 无法从 MasterViewController 访问 DetailViewController

ios - 从一个 View 到另一 View 更新标签内容

ios - UNUserNotificationCenterDelegate 委托(delegate)方法 "nearly matches optional requirement"

arrays - 将图像数组从 tableview 传递到 collectionview

swift - 将 UIBarButton Item 的点击区域扩展到屏幕边缘

iphone - 隐藏删除按钮时自定义 uitableviewcell 内容不动画

ios - segue完成后如何执行一些代码?

ios - 如何删除 Collection View 单元格之间的空间?

iphone - UITableView 单元格索引路径

objective-c - 使用 UITableViewCell 作为按钮