您不需要在應用程序委託中添加UITabBarController
,這只是最常用的方式。您可以讓初始視圖使用簡單的UIViewController
,然後當按下按鈕時加載UITabBarController
(以編程方式或從筆尖),然後顯示它。
下面是什麼可能是在你的應用程序代理的例子:
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// viewController is a UIViewController loaded from MainWindow.xib with a button that calls loadTabBarController
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (IBAction) loadTabBarController {
self.tabBarController = [[[UITabBarController alloc] initWithNibName:@"MyTabBarController" bundle:nil] autorelease];
[viewController.view removeFromSuperview];
[window addSubview:tabBarController.view];
}
我怎麼叫loadTabBarController如果我在另一個UIViewController中? – 2010-05-26 05:44:21
在我的示例中,它將在Interface Builder中進行連接。 MainWindow.xib將加載viewController。如果要以編程方式執行此操作,可以將該按鈕的目標設置爲應用程序委託並將其設置爲正常。 – 2010-05-26 06:01:47
可以說viewController有一個連接到Interface Builder中的IBAction的按鈕。 viewController如果在appDelegate中獲取對窗口的引用,該如何實現? – 2010-05-26 06:23:53