在創建我的第一個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