0

我正在使用 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];

}`

谢谢,

4

1 回答 1

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;
于 2012-08-16T06:26:57.057 回答