2011-03-04 66 views
1

我有一个基于窗口的应用程序。我添加了两个viewcontrollers和一个Tabbarcontroller。现在我想将每个viewcontroller导航到下一个视图。我试过但找不到解决方案。谁能帮帮我吗?如何将导航控制器添加到基于窗口的应用程序

+1

发表您的代码上,它可能更容易看到为什么事情都没有为你工作。 – Jamie 2011-03-04 05:23:27

回答

2

当您添加窗口上的标签栏,添加像这个 -

NSMutableArray * viewControllers = [[NSMutableArray alloc]init]; 


FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil]; 
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 
[firstViewController release]; 
[viewControllers addObject:nvc]; 
[nvc release]; 

SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; 
nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 
[secondViewController release]; 
[viewControllers addObject:nvc]; 
[nvc release]; 

UITabBarController * tabBarController = [[UITabBarController alloc] init]; 
tabBarController.viewControllers = viewControllers; 
[window addSubview:tabBarController.view]; 

编辑 - 每当你想在控制器中的任何一个进行导航。所有你需要的是拨打

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

而你会得到你想要的。 :)

1
UINavigationController *urNavController = [[UINavigationController alloc] initWithRootViewController:rootController]; 

如果你想显示这个窗口

[window addSubview:urNavController.view]; 
1

使用这样

secondViewController *obj=[[[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil] autorelease]; 
     UINavigationController *navBar=[[UINavigationController alloc] initWithRootViewController:obj]; 
     [self.navigationController pushViewController:navBar animated:YES]; 

     [navBar release]; 
相关问题