[英]Show login view controller before tab bar controller
我是iPhone開發的新手。 我正在開發一個包含四個選項卡的iphone應用程序。 我已經使用標簽欄控制器實現了它。 但是現在我需要在選項卡欄控制器之前顯示一個沒有選項卡的登錄屏幕。 我嘗試了很多方法,但沒有得到我想要的方法。
誰能用代碼片段解釋如何做到這一點?
創建一個新的類LoginViewController。 當您的應用程序啟動時,然后將視圖添加到窗口中。 現在,當登錄成功后,將其從超級視圖中刪除並添加MainController。
創建一個UITabBarController的子類(盡管蘋果不建議這樣做),但為此目的應該可以,並在viewWillAppear中進行此操作
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
BOOL isLogged in = //do something to determine if you're logged in
if(!loggedIn){
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewControllerNibHere" bundle:nil];
[self presentModalViewController:loginViewController animated:YES]; //or NO if you don't want it animated
[loginViewController release];
}
}
或將其添加到UITabBarController的類別中,並將其導入到應用程序委托中或使用UITabBarController的任何位置
最好的方法是創建一個新的LoginViewController,就像其他人提到的那樣,然后在對用戶進行身份驗證后立即將rootviewController設置為tabBarcontroller。 這是您快速執行此操作的方法,這是您在LoginViewController中對用戶進行身份驗證后的摘要
let tabBarController = self.storyboard?.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBarController
其中TabBarController是標簽欄控制器的情節提要ID。 可以是任何名稱,無論您使用什么名稱。
檢查此鏈接的源代碼,
它使用Login Controller作為具有4個選項卡的模式視圖
http://code.google.com/p/tweetero/source/checkout
我也嘗試過這種方式
在我的第一個標簽視圖中-在viewDidAppear
-我將檢查Login = YES,然后
顯示LoginController
- [self.tabbarcontroller presentMOdalViewcontroller:LoginView animated:YES];
因此,每次您單擊第一個選項卡時-如果您需要登錄,請添加一個標志-選中它並顯示登錄視圖
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.