简体   繁体   English

如何从嵌入在导航控制器中的简单视图控制器调用标签栏视图控制器?

[英]How to call tab bar view controller from simple view controller which is embedded in navigation controller?

How can I call TabbarViewControllers connected viewController from simple UIViewController where simple UIViewController is embedded in UINavigationController . 我怎么能叫从简单的UIViewController这里简单的UIViewController嵌入的UINavigationController连接的viewController TabbarViewControllers。 I want same Push and Pop effect which UINavigationController provide when moving one to other viewController. 我想要一个将UINavigationController移到另一个viewController时提供的相同的Push和Pop效果。 After digging in google I find out that pushing tab bar view controller inside navigation stack is not a good way to structure app. 深入研究google后,我发现在导航堆栈中推送标签栏视图控制器不是构建应用的好方法。 I tried creating custom transaction animation but it's not same like UINavigation transaction effect. 我尝试创建自定义交易动画,但它与UINavigation交易效果不同。 Please give some suggestion or solution. 请提供一些建议或解决方案。 Thanks!! 谢谢!!

You can directly set UITabbarController to window's rootViewController. 您可以直接将UITabbarController设置为窗口的rootViewController。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
_tabObj = (TabbarViewController*) [storyboard instantiateViewControllerWithIdentifier:@"TabbarViewController"];
self.window.rootViewController = _tabObj;

Check above code. 检查上面的代码。

as Nirmalsinh 's answer, you could set view controller that conform UITabBarControllerDelegate as your self.window.rootViewController , then should have UITabBarController inside it. 作为Nirmalsinh的答案,您可以将符合UITabBarControllerDelegate视图控制器设置为self.window.rootViewController ,然后在其中包含UITabBarController

var tabBarController: UITabBarController

then you can each of tab's navigation and view controller 然后您可以使用Tab的每个导航和视图控制器

let firstViewController = FirstViewController()
let firstNavigationController = UINavigationController(rootViewController: firstViewController)
// other setter

tabBarController.viewControllers = [
    firstNavigationController
]

then inside FirstViewController , you can call 然后在FirstViewController ,您可以调用

let secondViewController = SecondViewController()
navigationController?.pushViewController(SecondViewController, animated: true)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从标签栏视图 controller 转到另一个视图,该视图是导航 controller 的子视图 - How to segue from tab bar view controller to another view which is a child of a navigation controller 通过选项卡栏设置嵌入在Navigation Controller中的View Controller的属性 - Setting a property of a View Controller embedded in Navigation Controller via Tab Bar 如何快速隐藏嵌入在导航堆栈中的视图控制器中的选项卡栏? - how to hide tab bar in the view controller that embedded in the navigation stack in swift? 从导航栏视图控制器导航到选项卡栏视图控制器 - Navigate from a navigation bar view controller to a tab bar view controller 从选项卡栏控制器触发导航控制器中的视图控制器 - Trigger view controller in a navigation controller from tab bar controller 搜索到嵌入有选项卡和导航控制器的视图控制器 - Segue to a view controller embedded with a tab and navigation controller 如何将数据从一个视图控制器传递到导航控制器中嵌入的另一个视图控制器 - How to pass data from one view controller to another view controller which is embedded in navigation controller 带有简单视图控制器的导航栏 - Navigation bar with simple view controller 如何导航到标签栏控制器中嵌入的View Controller - How to navigate to a View Controller embedded in tab bar controller 从标签栏按钮将视图控制器推到导航控制器上 - Pushing a view controller onto a navigation controller from a tab bar button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM