简体   繁体   中英

Unable to set a UINavBarController as a UITabBarController

I am unable to set a certain tab view to be a UiNavigation controller. The warning I get is:

Pushing a navigation controller is not supported

Here is my code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1, *viewController2, *viewController3, *viewController4;
        viewController1 = [[HomeViewController alloc] initWithNibName:@"HomeViewController_iPhone" bundle:nil];
        viewController2 = [[SearchViewController alloc] initWithNibName:@"SearchViewController_iPhone" bundle:nil];
        viewController3 = [[ListViewController alloc] initWithNibName:@"ListViewController_iPhone" bundle:nil];
        viewController4 = [[InfoViewController alloc] initWithNibName:@"InfoViewController_iPhone" bundle:nil];

    self.tabBarController = [[UITabBarController alloc] init];
    UINavigationController * listNavController = [[UINavigationController alloc] initWithRootViewController:viewController3];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, listNavController, viewController4, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, listNavController, viewController4, nil];

to

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, viewController4, nil];

and keep a reference to the nav controller if needed. I think that would be the right way to do it, but you could also wrap the nav controller in a simple UIViewController. You would want to do this if viewController3 is not guaranteed to be the bottom most VC in your stack at all times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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