UINavigationController inside of UITabBarController issues

徘徊边缘 提交于 2019-12-25 04:19:52

问题


Can someone point me in the right direction with how to set up a UINavigationController inside of a UITabBarController? I have a feeling I'm using initWithRootViewController wrong.

ViewController1 *viewController1 = [[[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil] autorelease];
self.navController = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
ViewController2 *viewController2 = [[[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil] autorelease];
ViewController3 *viewController3 = [[[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:nil] autorelease];
ViewController4 *viewController4 = [[[ViewController4 alloc] initWithNibName:@"ViewController4" bundle:nil] autorelease];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
_tabBarController.viewControllers = [NSArray arrayWithObjects:navController, viewController2, viewController3, viewController4, nil];

self.tabBarController.delegate = self;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

Thanks for any tips guys.


回答1:


In the AppDelegate, you put this:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
     // Override point for customization after application launch.
     UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
     UINavigationController *navC1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
     UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
     UINavigationController *navC2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
     UIViewController *viewController3 = [[[FirstViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease];
     UINavigationController *navC3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
     UIViewController *viewController4 = [[[SecondViewController alloc] initWithNibName:@"ForthViewController" bundle:nil] autorelease];
     UINavigationController *navC4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
     self.tabBarController = [[[UITabBarController alloc] init] autorelease];
     self.tabBarController.viewControllers = [NSArray arrayWithObjects:navC1, navC2, navC4, navC4, nil];
     self.window.rootViewController = self.tabBarController;
     [self.window makeKeyAndVisible];
     return YES;

}

Hope that help (Sorry for the bad english :-) );



来源:https://stackoverflow.com/questions/9356819/uinavigationcontroller-inside-of-uitabbarcontroller-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!