简体   繁体   English

Segue到TabBar控制器

[英]Segue to TabBar Controller

I'm using the following code to perform a segue to another view controller: 我正在使用以下代码对另一个视图控制器执行segue:

[self performSegueWithIdentifier:@"BackSegue" sender:self];

This works fine when the destination of "BackSegue" named segue is another view controller (one of the tabs, actually) but I need to display the tabs at the bottom so transitioning directly to this view controller won't work as there will be no tabs. 当名为“ segue”的“ BackSegue”的目的地是另一个视图控制器(实际上是选项卡之一)时,此方法很好,但是我需要在底部显示选项卡,因此直接过渡到该视图控制器将无法工作,因为将没有标签。 Is it allowed/possible to segue to a tabbar controller? 是否可以/可以锁定到标签栏控制器? Is anything wrong with this specific code or would it be something else I'm doing? 这个特定的代码有什么问题吗,还是我在做其他事情?

Edit 1 编辑1

The TabBar controller has no .m/.h files and is never declared programmatically, but I'm pretty sure the segue is set up correctly in the storyboard to the best of my knowledge (the same way it was set up earlier directly to the other viewcontroller). TabBar控制器没有.m / .h文件,也从未通过编程方式声明过,但是我敢肯定,就我所知,segue在故事板上的设置是正确的(与之前直接设置为其他ViewController)。

You can segue directly to a UITabBarController . 您可以直接选择UITabBarController Just change the segue in your storyboard. 只需在情节提要中更改序列即可。 When the segue occurs, it should load the tab bar controller, and consequently the tab bar at the bottom of the screen and the first view controller's view associated with the tab bar controller. 发生segue时,它应该加载选项卡栏控制器,并因此加载屏幕底部的选项卡栏以及与该选项卡栏控制器关联的第一个视图控制器的视图。

In order to segue to the specific tab in the tab bar controller: You need to add the selectedIndex=1 为了选择标签栏控制器中的特定标签:您需要添加selectedIndex = 1

Add these lines of code for segue: 添加以下代码行进行segue:

UITabBarController *loadTabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TasksAppsTabs"];
        loadTabBar.selectedIndex=1;
        [self presentViewController:loadTabBar animated:YES completion:nil];

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM