我是xcode的新手,並試圖瞭解UITabBarController的工作原理。我一直在尋找,找不到解決這個問題的直接辦法。在我看到的大多數示例/教程中,UITabBarController是在AppDelegate中定義的,然後一旦啓動應用程序,就會立即看到選項卡欄。在我的應用程序中,我想先顯示一個歡迎屏幕,然後一旦點擊「Enter」,就會進入tabbar視圖。所以我的對象的理想結構如下所示:TabBar/UITabBarController實現的選項
MyProjectAppDelegate - > MyProjectViewController - >的firstView/SecondView
據我瞭解,有關什麼的TabBar然後應在MyProjectAppDelegate宣稱這種結構。我嘗試着看一些UITabBarController在AppDelegate中聲明並在MyProjectViewController中執行相同的例子,但沒有任何反應。
例如,我連接到「輸入」的UIButton我的歡迎屏幕上的IBAction爲內做這在我的MyProjectViewController:
- (IBAction) EnterApp {
[window addSubview:tabBarController.view];
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
FirstView* first = [[FirstView alloc] init];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:first];
SecondView* second = [[SecondView alloc] init];
UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:second];
NSArray* controllers = [NSArray arrayWithObjects:firstNav,secondNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
}
同樣,這也沒做什麼,一旦我點擊了「輸入「按鈕,即使它在我從它拿起它的例子中(它在AppDelegate中的位置)執行作業
我也在我的MyProjectViewController上試過這個,其中tabbar確實顯示在第一個/第二個視圖上,但沒有選擇自定義它(只是空白的黑條沒有任何關於它們,不知道在哪裏配置它們):
- (IBAction) EnterApp {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
UIViewController *viewController2 = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
這裏出了什麼問題,應該怎麼做纔是正確的做法?一個快速的例子將不勝感激。
謝謝!
我試圖避免使用的通知,並改變了我的AppDelegate太多(我可能有幾個標籤欄以後和不想要弄糟了應用程序委託 - 更喜歡更模塊化的設計)。儘管謝謝! – TommyG