在目标c中使用Tab Bar控制器获取黑屏

时间:2015-02-26 08:32:56

标签: ios

我有这个代码来显示一个标签栏控制器,它有两个标签,工作正常。

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;

在Class1类中,它是Tab1,它有一个指向AnotherClass1的按钮,在ANotherClass1中它有一个指向AnotherClass3的按钮。问题是,在AnotherClass3中它有一个返回MainViewController.h的按钮

AnotherClass3.h

//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时,它将显示2个选项卡。

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

0 个答案:

没有答案
相关问题