UITabBarController 问题中的 UINavigationController

Posted

技术标签:

【中文标题】UITabBarController 问题中的 UINavigationController【英文标题】:UINavigationController inside of UITabBarController issues 【发布时间】:2012-02-20 06:01:32 【问题描述】:

有人能指出我正确的方向吗?如何在 UITabBarController 中设置 UINavigationController?我感觉我在使用 initWithRootViewController 错误。

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];

感谢任何提示。

【问题讨论】:

【参考方案1】:

在 AppDelegate 中,您输入以下内容:

 - (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;


希望有所帮助(抱歉英语不好:-));

【讨论】:

感谢阿尔贝托的回复。当我回到那个问题并报告回来时,我会对此进行测试。

以上是关于UITabBarController 问题中的 UINavigationController的主要内容,如果未能解决你的问题,请参考以下文章

UITabBarController 问题中的 UINavigationController

iOS,UITabBarController 中的问题

嵌入在 NavigationController 中的 UITabBarController

ios 6 中的 UITabBarController 旋转问题

UITabBarController 中的 UINavigationController 没有完全包裹 UIViewController

以编程方式将 UITabBarController 中 TabBarItem 中的图标居中