簡體   English   中英

在選項卡控制器視圖之前顯示登錄屏幕

[英]Show login screen before tab-controller view

我有一個tabBarController應用程序,並且使用.xib文件作為界面而不是情節提要我默認在appdelegate中有此代碼

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[PopAdsFirstViewController alloc] initWithNibName:@"PopAdsFirstViewController" bundle:nil];

UIViewController *viewController2 = [[PopAdsSecondViewController alloc] initWithNibName:@"PopAdsSecondViewController" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];

self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];

return YES;

我創建了一個登錄視圖,不知道如何在tabBarView之前顯示它,並在成功登錄后隱藏t。

一種方法是在啟動時將其顯示為modalView。 成功登錄后退出嗎? 例如:

UIViewController myLoginViewController = [[MyLoginViewController alloc] init withNibNamed:"MyLoginViewController"]; //Or whatever you instantiation is
[myTabViewController presentModalViewController:myLoginViewController animated:YES];

並將其關閉(隱藏)

//This should be done from the original View Controller i.e. myTabViewController preferably in a delegate called by the modal view controller.
[self dismissModalViewControllerAnimated:YES];

有關modalViewControllers的文檔: http : //developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

我為其中一個應用程序執行此操作的方法是,僅以正確的順序添加它們。 將標簽欄控制器添加到窗口,然后在標簽欄頂部添加登錄控制器。 然后顯示您的窗口。 除了您的登錄控制器,該用戶什么都看不到。 登錄后,您只需從視圖中刪除登錄控制器即可。

如果您有需要隱藏直到登錄的信息,這種方式可能是最好的。 另一種方法是僅啟動登錄視圖。 成功登錄后,刪除登錄並添加標簽欄控制器。 兩種方法都可以。

模態演示可能是最簡單的,但是在演示之前需要有適當的視圖。 因此,如果登錄控制器下的數據和視圖不那么敏感,則可以考慮使用此選項。

另一種方法是在appDelegate.h文件中使用LoginViewControllerDelegate

在您的.h中

    #import "yourLoginViewController"
   //and add LoginViewControllerDelegate

然后在您的.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    yourLoginViewController *loginView = [[yourLoginViewController alloc] initWithNibName:@"yourLoginViewController" bundle:nil];
    loginView.delegate = self;
    [window addSubview:loginView.view];
    [window makeKeyAndVisible];
}
//add this one
- (void)loginViewControllerDidFinish:(yourLoginViewController *)loginViewController {
    [window addSubview:tabBarController.view];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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