问题描述
我正在尝试使用以下代码来显示tabbarcontroller
I'm trying to use the following code to display a tabbarcontroller
UITabBarController *tc = [[self storyboard] instantiateViewControllerWithIdentifier:@"tabbarcontroller"];
[self.navigationController pushViewController:tc animated:YES];
它确实加载了视图,我可以告诉它要将其默认设置为哪个选项卡.问题是选项卡不显示.根据我的阅读,我认为这与将Tab控制器放入导航控制器有关,但是我找不到任何解决方案.
It does load the view, and I can tell it which of the tabs I want it to default to. The problem is the tabs don't show. From what I've read I gather it has something to do with putting the tab controller inside of the navigation controller, but I couldn't find any solutions.
推荐答案
如果使用Storyboard,则使用pushViewController方法是一个不好的选择(如果可行).您必须插入" segue ".进入情节提要,然后在按住的同时按Ctrl键,单击主控制器(必须打开tabViewController),然后释放对tabBarController的单击.
If you use Storyboard, use pushViewController method is a bad choice (also if it work). You have to insert a "segue".Go in the storyboard and while press ctrl button, click on the main controller (which must open the tabViewController) and then release the click on the tabBarController.
现在您拥有了segue.单击出现的圆圈,然后为此标识选择一个标识符,例如: MainToTab .
Now you have the segue. Click on the circle which appears and choose an identifier for this segue, for example: MainToTab .
现在,在您的方法中,您只需调用:
Now in your method, you have just to call:
[self performSegueWithIdentifier:@"MainToTab" sender:self];
此外,如果要(通过segue)管理目标控制器上的属性,则可以实现此方法:
Moreover, if you want manage the property on the destination controller (by segue), you can implement this method:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"MainToTab"]) {
UITabViewController *tb = (UITabViewController *)segue.destinationViewController;
//set the properties...
}
}
启动前一种方法时会自动调用此方法.
This method is called automatically when you launch the previous method.
这篇关于使用PushViewController时不显示选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!