UITabBarController only showing half of its UITabBar (off screen)

后端 未结 2 1261
长发绾君心
长发绾君心 2021-01-24 05:05

My UITabBar is not completely showing after I present a UITabBarController from a UIViewController. Please can you tell me what I am doing wrong?

My code is:

<         


        
相关标签:
2条回答
  • 2021-01-24 05:24

    Actually according to the Apple's recommendations UITabBarViewController should be the root in the UIWindow hierarchy. We had hard times trying to put TabBar VCs or Navigation VCs not to the root.

    0 讨论(0)
  • 2021-01-24 05:41

    It's not a good practice to do:

    [viewController1.view addSubview:viewController2.view];
    

    The point of the MVC design is lost. The view controller should get your data (from the model) and put it in the view. If you have more than one view just arrange the functionality of the views to accept the corresponding data.

    So if you need a tab bar controller you should do the following:

    // assuming you are in the same initial controller
    UITabBarController* pTabBarControllerL = [[UITabBarController alloc] init];
    MyFirstController* pFirstControllerL = [[MyFirstController alloc] init];
    [pTabBarControllerL setViewControllers:[NSArray arrayWithObject:pFirstControllerL]];
    // perhaps set more tab bar controller properties - button images and so on
    [self presentModalViewController:pTabBarControllerL animated:YES];
    // release the memory you do not need
    
    -(void)viewDidLoad {
        // do your work in pFirstControllerL
    }
    

    PS: You should not subclass UINavigationController and UITabBarController.

    0 讨论(0)
提交回复
热议问题