[英]Move from one tab bar to another on click (Tab bar with navigation controllers)
Hi all I want to segue from first tabbarcontroller to second tabbarcontroller but not able to do so. 大家好我想从第一个tabbarcontroller到第二个tabbarcontroller但不能这样做。 View Controllers in my TabBar are also embedded with NavigationControllers ,and so when i try to switch tabs it gives me error saying-: 我的TabBar中的View Controllers也嵌入了NavigationControllers,所以当我尝试切换标签时,它给出了错误说 - :
Could not cast value of type 'UINavigationController' (0x1048d5898) to 'abc.CategoriesController' (0x101088d88). 无法将'UINavigationController'类型的值(0x1048d5898)转换为'abc.CategoriesController'(0x101088d88)。
Code I used-: 我使用的代码 - :
let barViewControllers = self.tabBarController?.viewController
let svc = barViewControllers![1] as! myController
svc.myOrder = self.myOrder
I tried many solutions but failed to segue can anyone help me? 我尝试了很多解决方案,但是没有人能帮助我吗? Please explain me concept behind this if anyone can? 如果有人可以,请解释我背后的概念吗?
self.tabBarController.selectedIndex = 1
does work but I can not pass data with this method. self.tabBarController.selectedIndex = 1
确实有效但我无法使用此方法传递数据。
As Maddy said-: 正如Maddy所说:
Use let barViewControllers = self.tabBarController?.viewController[1] as? myController
使用let barViewControllers = self.tabBarController?.viewController[1] as? myController
let barViewControllers = self.tabBarController?.viewController[1] as? myController
to pass data. let barViewControllers = self.tabBarController?.viewController[1] as? myController
传递数据。
But this is the line that gives me above crash 但这就是让我崩溃的路线
The error you got suggest that what you getting from the below code is not the viewController if you 你得到的错误表明你从下面的代码得到的不是viewController,如果你
let barViewControllers = self.tabBarController?.viewController //some what wrong with this
best way to access all view controller is as below 访问所有视图控制器的最佳方法如下
var svc = self.tabBarController.viewControllers
and if you want to access viewControllers by index of them then below one 如果你想通过索引访问viewControllers然后低于一个
var svc = self.tabBarController.viewControllers[1] as yourVC
and last but not in list if you want to access navigation controller from the tabbar 如果要从标签栏访问导航控制器,请在列表中输入最后但不在列表中
var svc = self.tabBarController.viewControllers[1] as UINavigationController
Hope this help you :) 希望这对你有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.