简体   繁体   English

无法将UINavBarController设置为UITabBarController

[英]Unable to set a UINavBarController as a UITabBarController

I am unable to set a certain tab view to be a UiNavigation controller. 我无法将某个选项卡视图设置为UiNavigation控制器。 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. 我认为这是正确的方法,但是您也可以将导航控制器包装在一个简单的UIViewController中。 You would want to do this if viewController3 is not guaranteed to be the bottom most VC in your stack at all times. 如果不保证viewController3始终是堆栈中最底层的VC,则需要执行此操作。

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

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