在创建我的第一个iPhone应用程序的斗争中,我注意到苹果的例子有一个tabbar或导航栏,但从来都没有。带有tabbar和导航控制器的iOS应用程序
可以做到这一点吗?
所以我在这里有3个按钮的标签栏,我现在怎样才能将一个导航控制器添加到我的整个应用程序中?
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *activityViewController = [[[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:nil] autorelease];
UIViewController *agendaViewController = [[[AgendaViewController alloc] initWithNibName:@"AgendaViewController" bundle:nil] autorelease];
UIViewController *settingsViewController = [[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:activityViewController, agendaViewController, settingsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
编辑:
我真的不继,所以在我的appdelegate我创建了一个navigationController和使用,作为RootViewController的。
然后,我创建了一个tabBarController并添加到了我的窗前
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UINavigationController *mainViewController = [[UINavigationController alloc] init];
self.mainViewController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
self.window.rootViewController.title = @"test";
MainViewController *tabBarController = [[MainViewController alloc] init];
[self.window addSubview:tabBarController.view];
但每当我跑,我得到错误”
推导航控制器,不支持
我还缺少什么吗?
他希望整个应用程序的navigationController。所以它必须是根 – Fab1n
,如果他初始化标签栏控制器,如我在AppDelegate.m中所述,然后self.window.rootController = tabBarController;它会工作。 – Anila