簡體   English   中英

在IOS的Cocoa Touch Tab Bar Application前面添加登錄屏幕

[英]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];

如果從默認選項卡欄應用程序開始,則可以這樣操作:

  • 在MainWindow.xib中,創建一個UIView,其中包含您希望在密碼屏幕上擁有的所有內容
  • 在AppDelegate中將所需的任何內容掛接到IBOutlets,然后編寫檢查密碼是否有效的方法。
  • 在applicationDidFinishLaunching方法中,替換[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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM