如何使用带有NavigationController的TabBarViewController

时间:2011-06-16 01:24:41

标签: iphone objective-c ios xcode

我知道我可以做到这一点

 [self.navigationController pushViewController:self.someUITabBarController animated:YES];

这意味着UITabBarController以某种方式navigationgController

如果我希望someUITabBarController成为navigationController的第一个控制器(位于最低级别的控制器),该怎么办?

我无法将rootViewController的{​​{1}}更改为NavigationController

2 个答案:

答案 0 :(得分:2)

嗯,不确定这是你想要的。此代码下方将放在您“appDelegate”类中的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions下。

UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = ...
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController1];

NSArray *controllers = [NSArray arrayWithObjects:navigationController, nil]; // can add more if you want

[tabController setViewControllers:controllers];

// this is for custom title and image in the tabBar item
navigationController.tabBarItem.title = @"abc";
[navigationController.tabBarItem setImage:[UIImage imageNamed:@"abc.png"]];

self.window.rootViewController = tabController; // or [self.window addSubview: tabController.view];
[self.window makeKeyAndVisible];

答案 1 :(得分:1)

我不确定这是否有效。但试试这个,

UINavigationController *navCont = [[UINavigationController alloc] init];
[navCont pushViewController:navCont animated:NO];