我正在使用Xcode 4.4.1。我创建了一个简单的基于标签的应用程序。然后我想在应用程序中添加导航控制器。任何人都可以告诉我如何在Xcode 4.4.1中做到这一点。我目前的代码是这样的,但它不起作用。
`
- (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 :(得分: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;