[英]What are the conventions for declaring a UITabBarController in mainwindow.xib?
[英]Display XIB before UITabBarController?
我幾個月來一直面對這個問題,我不知道什么是解決該問題的最佳方法。問題是,我需要在UITabBar出現之前先加載XIB,更清楚地說,我有我的第一個觀點這是針對用戶登錄(不應顯示TABBAR),當用戶登錄時,應用會驗證信息,並在之后使用UITabBarController加載視圖,但是每次我嘗試這樣做時都不會模態顯示登錄視圖,顯示視圖,登錄視圖和選項卡視圖。
您可以先將loginViewController設置為主window
rootViewController
,然后在用戶登錄rootViewController
設置為rootViewController
。
這樣的事情(假設您的loginViewController是viewController1
):
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UINavigationController *myNav1=[[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *myNav2=[[UINavigationController alloc] initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:myNav1,myNav2, nil];
//set the login view
self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}
-(void)setTabBar{
//self.viewController1=nil;
self.window.rootViewController = self.tabBarController;
}
然后從loginViewController調用setTabBar
的setTabBar方法。
LoginViewController.m
#import "AppDelegate.h"
-(void)loginOK{
AppDelegate *del=(AppDelegate*)[[UIApplication sharedApplication] delegate];
[del setTabBar];
//you could add some animation transition between views
}
據我所知, UITabBarController
不能被嵌入到另一個viewController
。 考慮到這一點,您有以下選擇:
呈現模態視圖(您不需要)
在啟動時隱藏tabBar
,並在驗證憑據后顯示tabBar
。 但是有一個缺點:隱藏/顯示tabBar
不能設置動畫。
您可以僅使用一個viewController
來啟動UITabBarController
一個將要求提供憑據的viewControllers
,並且在驗證后,向UITabBarController
添加更多viewControllers
(這將添加更多選項卡)。 您也可以在某些應用程序中看到這種行為,例如,美國銀行 (http://itunes.apple.com/us/app/bank-america-mobile-banking/id284847138?mt=8)
可能會有更好的做法。 這些是我的建議。
作為一種簡單的方法,將視圖添加為窗口的子視圖,並在不再需要它時將其關閉。
例如,將此代碼放在您的appdelegate中(假設loginController
是您的appdelegate的屬性...還有其他方法,這只是一個示例):
[self.window addSubview:self.loginController.view];
當您想要關閉視圖時,將其刪除:
[self.loginController.view removeFromSuperview];
不要忘記正確釋放loginController
。
這樣,您的視圖只是簡單地“覆蓋”在標簽欄視圖上。 如果您要這樣做,這里還有其他答案,僅在完成登錄后才有效地將標簽欄視圖交換到視圖層次結構中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.