Ios 在objective c中使用Tab-Bar控制器获取黑屏

Ios 在objective c中使用Tab-Bar控制器获取黑屏,ios,Ios,我有这个代码来显示一个选项卡栏控制器,它有两个选项卡,它工作得很好 MainViewController.h UIViewController *viewController1 = [[Class1 alloc] initWithNibName:@"Class1" bundle:nil]; UIViewController *viewController2 = [[Class2 alloc] initWithNibName:@"Class2 " bundle:nil]; [getUI nav

我有这个代码来显示一个选项卡栏控制器,它有两个选项卡,它工作得很好

MainViewController.h

UIViewController *viewController1 = [[Class1 alloc] initWithNibName:@"Class1" bundle:nil];

UIViewController *viewController2 = [[Class2 alloc] initWithNibName:@"Class2 " bundle:nil];

[getUI navigationAppearance];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];

//object to customize tabBar
[getUI customTabBar:self.tabBarController];

[self.navigationController pushViewController:self.tabBarController animated:YES];
self.tabBarController.navigationController.navigationBarHidden = NO;
//This for loop iterates through all the view controllers in navigation stack.

for (UIViewController* viewController in self.navigationController.viewControllers) {

    //This if condition checks whether the viewController's class is MyGroupViewController
    // if true that means its the MyGroupViewController (which has been pushed at some point)
    if ([viewController isKindOfClass:[MenuViewController class]] ) {

        // Here viewController is a reference of UIViewController base class of MyGroupViewController
        // but viewController holds MyGroupViewController  object so we can type cast it here
        //self.navigationController.navigationBarHidden = YES;
        MenuViewController *groupViewController = (MenuViewController*)viewController;
        [self.navigationController popToViewController:groupViewController.tabBarController animated:YES];

    }
}
在Class1类中,即Tab1,它有一个到另一个Class1的按钮,在另一个Class1中,它有一个到另一个CLASS3的按钮。现在的问题是,在另一个Class3中,它有一个返回MainViewController.h的按钮

其他类别3.h

UIViewController *viewController1 = [[Class1 alloc] initWithNibName:@"Class1" bundle:nil];

UIViewController *viewController2 = [[Class2 alloc] initWithNibName:@"Class2 " bundle:nil];

[getUI navigationAppearance];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];

//object to customize tabBar
[getUI customTabBar:self.tabBarController];

[self.navigationController pushViewController:self.tabBarController animated:YES];
self.tabBarController.navigationController.navigationBarHidden = NO;
//This for loop iterates through all the view controllers in navigation stack.

for (UIViewController* viewController in self.navigationController.viewControllers) {

    //This if condition checks whether the viewController's class is MyGroupViewController
    // if true that means its the MyGroupViewController (which has been pushed at some point)
    if ([viewController isKindOfClass:[MenuViewController class]] ) {

        // Here viewController is a reference of UIViewController base class of MyGroupViewController
        // but viewController holds MyGroupViewController  object so we can type cast it here
        //self.navigationController.navigationBarHidden = YES;
        MenuViewController *groupViewController = (MenuViewController*)viewController;
        [self.navigationController popToViewController:groupViewController.tabBarController animated:YES];

    }
}
请注意,当我返回MainViewController.h时,它将显示两个选项卡


在20次测试中,19次可以正常工作,但1次会出现黑屏,我不知道为什么,我真的需要你的帮助。谢谢

嘿,谁能回答我的问题???