简体   繁体   English

为什么选项卡栏没有显示在我的视图控制器上?

[英]Why doesn't the tab bar show up on my view controllers?

I have the following in Interface Builder: 我在Interface Builder中具有以下内容: 在此处输入图片说明

The top left is my main view controller where I have 2 buttons that have segue to two UIViewControllers. 左上方是我的主视图控制器,其中有2个按钮分别与两个UIViewControllers相连。 These two UIViewControllers are linked with the Tab Bar Controller. 这两个UIViewControllers与Tab Bar Controller链接。 However, how could I make those 2 buttons to link to specifically to one/other views? 但是,如何使这两个按钮专门链接到一个/其他视图? Right now it's connected specifically, but it (or something else) causes the bar tab not show up. 现在,它已专门连接,但是(或其他原因)导致条形标签未显示。

Is it the problem that I don't have the Tab Bar Controller connected to the main view? 我没有将标签栏控制器连接到主视图吗?

Yes, you're right that the problem occurs because the tab bar controller needs to be the destination of the segues. 是的,您没错,因为选项卡栏控制器必须是segue的目的地,所以会出现问题。 Fix it like this: 像这样修复它:

In IB, erase the segues from the two buttons and create two new ones, one from each button to the tab bar controller . 在IB中,清除两个按钮的序列,然后创建两个新序列,每个按钮到选项卡栏控制器的一个 Give each one an identifier, like buttonA from one button and buttonB from the other. 给每个人一个标识符,例如一个按钮的buttonA和另一按钮的buttonB

In the view controller, implement prepareForSegue for each segue understanding that the destination is a tab bar controller and that each segue requires a different tab selection... 在视图控制器中,为每个序列实现prepareForSegue ,了解目标是一个标签栏控制器,并且每个序列都需要不同的选项卡选择...

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"buttonA"]) {
        UITabBarController *tabBarController = (UITabBarController *)segue.destinationViewController;
        tabBarController.selectedIndex = 0;
    }
    if ([segue.identifier isEqualToString:@"buttonB"]) {
        UITabBarController *tabBarController = (UITabBarController *)segue.destinationViewController;
        tabBarController.selectedIndex = 1;
    }
}

That's not quite how the tabBarController works. 这不是tabBarController工作方式。

I can see your initial view controller is the one on the top left, and it pushes either of the other two on the right on to the navigation stack if you push a button. 我可以看到您的初始视图控制器是左上角的控制器,如果按下按钮,它将把其他两个右任一个推入导航堆栈。 But in your current setup, at no point does the tab controller itself get pushed on to the stack. 但是在当前设置中,选项卡控制器本身绝不会压入堆栈。

Instead, you would want to have your initial view controller push the tab bar controller on to the stack, through a button or otherwise, and the tab bar controller will display your other two view controllers as its setup to do. 取而代之的是,您希望您的初始视图控制器通过按钮或其他方式将选项卡栏控制器推到堆栈上,并且选项卡栏控制器将显示您的其他两个视图控制器作为其设置。

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

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