将数据从tableview传递到Swift中的标签栏视图控制器. [英] Pass data from tableview to tab bar view controller in Swift.

查看:78
本文介绍了将数据从tableview传递到Swift中的标签栏视图控制器.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的情节提要中,我有一个部分,其中带有表视图的视图控制器放置在选项卡栏控制器之前.该选项卡栏有两个视图控制器.之前我已经使用过表格视图,当我单击一个单元格时,我传递给另一个Viewcontroller,该控件又向另一个视图控制器加载了表格和具有来自第一个表格的推入单元格的ID的单元格.像这样:

At my storyboard I have a part where a view controller with a table view is placed before a tab bar controller. This tab bar has two view controllers. Earlier I used the table view already, and when I clicked on one cell I passed to another Viewcontroller which loaded another view controller with table and cells with the id from the pushed cell from the first table. Like this:

tableview控制器,为segue做准备:

The tableview controller, prepare for segue:

        if segue.identifier == "overviewSegue" {
          var caseViewController: CaseViewController = segue.destinationViewController as CaseViewController
          var caseIndex = overviewTableView!.indexPathForSelectedRow()!.row
          var selectedCase = self.cases[caseIndex]
        caseViewController.caseitem = selectedCase
    }

这很好.现在我想做同样的事情,但是唯一的区别是最后一个视图控制器是标签栏控制器的一部分.问题是我无法使其将数据传递到最后一个表视图控制器.

This works well. Now I want to do the same, but the only difference is that the last view controller is part of a tabbar controller. The problem is I can't get it working to pass the data to this last table view controller.

我尝试了几件事,但无法将数据指向标签栏表视图. Segue的访问不是很容易,目的地不是表视图控制器,而是Tabbar控制器等.问题是如何将数据从Tableview通过Tabbar控制器传递到另一个View Controller.

I tried several things, but I can't point the data to the tabbar table view. Segue's are not approachable, and the destination isn't the table view controller, but the tabbar controller, etc. The question, how to pass data from a tableview through the tabbar controller to another view controller.

推荐答案

我找到了一个解决方案:

I have found a solution:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
      if segue.identifier == "toTabController" {
        var tabBarC : UITabBarController = segue.destinationViewController as UITabBarController
        var desView: CaseViewController = tabBarC.viewControllers?.first as CaseViewController

        var caseIndex = overviewTableView!.indexPathForSelectedRow()!.row
        var selectedCase = self.cases[caseIndex]

        desView.caseitem = selectedCase
      }
    }

简单的解释:您需要进入Tab栏控制器并选择他的视图控制器.它通常有两个,因此您可以选择第一个.之后,定义它属于哪个类,您可以像以前一样传递数据.

Easy explanation: You need to get to your Tab bar controller and pick his view controllers. It normally has two, so you can pick the first. After that, define which class it belongs to, and you can pass your data just as you did before.

这篇关于将数据从tableview传递到Swift中的标签栏视图控制器.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆