2012-08-16 72 views
0

我正在使用Xcode 4.4.1。我创建了一个简单的基于选项卡的应用程序。然后我想将导航控制器添加到应用程序中。任何人都可以告诉我如何在Xcode 4.4.1中做到这一点。我目前的代码是这样的,但它不起作用。如何将NavigationController添加到iOS中的基于标签的应用程序中

`

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

{

// Override point for customization after application launch. 
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
UIViewController *viewController2 = [[Addbills alloc]initWithNibName:@"Addbills" bundle:nil]; 
UIViewController *viewController3 = [[CalenderView alloc]initWithNibName:@"CalenderView" bundle:nil]; 
UIViewController *viewController4 = [[Web alloc]initWithNibName:@"Web" bundle:nil]; 
UIViewController *viewController5 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController1]; 
[self.navigationController setNavigationBarHidden:TRUE]; 


self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = @[viewController1,viewController2,viewController3,viewController4,viewController5]; 
self.window.rootViewController = self.tabBarController; 

// self.window.rootViewController = self.navigationController;

[self.window addSubview:navigationController.view]; 
[self.window makeKeyAndVisible]; 
return YES; 

}

`

,这是我的viewController5按钮单击事件

`

- (IBAction)backToPrevious:(id)sender { 


[self.navigationController popToRootViewControllerAnimated:TRUE]; 

}`

感谢,

回答

0

下面是你应该怎么做。

// initialize the tabbar controller 
UITabBarController *tabbarController = [[[UITabBarController alloc] init] autorelease]; 

UIViewController *itemsViewController1 = [[[UIViewController alloc] initWithNibName:@"SomeViewController1" bundle:nil] autorelease]; 
UINavigationController *itemsNavigationController1 = [[UINavigationController alloc] initWithRootViewController:itemsViewController1]; 

UIViewController *itemsViewController2 = [[[UIViewController alloc] initWithNibName:@"SomeViewController2" bundle:nil] autorelease]; 
UINavigationController *itemsNavigationController2 = [[UINavigationController alloc] initWithRootViewController:itemsViewController2]; 


tabbarController.viewControllers = @[itemsNavigationController1,itemsNavigationController2]; 

_window.rootViewController = tabbarController; 
+0

因为我有5个选项卡,我创建5个对象为AppDelegate.m每个标签和在5日的ViewController BTN点击为 [self.navigationController popToRootViewControllerAnimated:TRUE],但它不是去到另一个页面 – iDia 2012-08-16 07:01:25

相关问题