[英]Adding login screen in front of Cocoa Touch Tab Bar Application for IOS
仍然在這里繞開我的腦袋。 我什至沒有關閉,但是無論如何...。我有一個從Xcode創建的TabBar應用程序。 它的工作原理是我有三個選項卡視圖,知道如何操作等。
我想在整個過程前放置一個“ login” nib文件,要求用戶回答一個(目前已硬編碼)用戶名和密碼。 如果正確,則渲染選項卡部分,允許他們單擊。
我已經編寫了另一個應用程序,該應用程序負責用戶名和密碼部分,我無法從那里獲取邏輯並將其放在TabApplication部分的前面。
有人有什么建議嗎?
在您的AppDelegate中,在application didFinishLaunchingWithOptions
方法末尾,您將看到以下內容:
[window addSubview:tabcontroller.view];
[window makeKeyAndVisible];
return YES;
只需初始化您的登錄視圖控制器並將其添加到tabcontroller之后,如下所示:
initialScreenViewController = [[InitialScreenViewController alloc] init];
[window addSubview:tabcontroller.view];
[window addSubview:initialScreenViewController.view];
[window makeKeyAndVisible];
return YES;
在登錄viewcontroller中,對用戶進行身份驗證后,可以像這樣隱藏它:
[self.parentViewController.view setHidden:YES];
如果您具有退出功能,則可以再次顯示它。
標准方法如下:
UIViewController
子類中。 通過調用在application:didFinishLaunchingWithOptions:
中的應用程序委托中以模態形式顯示該視圖
LoginController*loginController= ... ; // create the view controller for the login screen [self.tabController presentModalViewController:loginController animated:YES];
這樣,將自動處理過渡等之間的動畫。
您可以稍后在成功登錄后將其關閉。可以通過在LoginController
內部執行以下操作:
[self.parentViewController dismissModalViewControllerAnimated:YES];
但是,登錄完成后,我經常需要進行其他設置。 因此,我首先要告訴應用程序代表登錄已完成,然后執行
[self.tabController dismissModalViewControllerAnimated:YES];
來自應用程序委托。 然后,我可以在那里執行其他任務。
為了與應用程序NSNotification
通信,我將使用NSNotification
,但這對您來說可能有點困難。
一種可能更容易理解(但loginDone
我口味)的方法是定義一個方法,例如在應用程序委托中使用loginDone
。 然后,在LoginViewController
,您可以執行
MyAppDelegate*appDelegate=[[UIApplication sharedApplication] delegate];
[appDelegate loginDone];
如果從默認選項卡欄應用程序開始,則可以這樣操作:
[window addSubview:tabBarController.view];
與[window addSubview:/*whatever you called the view with the password stuff in it*/];
[passView removeFromSuperview]; [window addSubview:tabBarController.view];
並且您應該在常規的標簽欄應用程序中。
我更喜歡執行以下操作:
在App Delegate的didFinishLaunchingWithOptions
:
FirstViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
ThirdViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[navController1, navController2, navController3];
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
UINavigationController *loginNavController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
self.window.rootViewController = loginNavController;
然后,在獲得身份驗證回調后,您可以在App Delegate中添加以下內容:
- (void)setAuthenticatedState:(BOOL)authenticated
{
if (authenticated == YES) {
dispatch_async(dispatch_get_main_queue(), ^(){
self.window.rootViewController = self.tabBarController;
});
}else{
// Stuff
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.