2011-12-21 56 views
1

我有一個tabBarController應用和使用的.xib文件的界面不是故事板 我都默認這個代碼顯示登錄屏幕前標籤控制器視圖

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; 

我創建了一個登錄查看的appdelegate並且不知道如何在tabBarView之前顯示它,並在成功登錄後隱藏t。

回答

6

一種方法是在啓動時將其顯示爲模態視圖。在成功登錄時忽略? 如:

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

+0

它的工作原理可以用LoginViewControllerDelegate在您的.h

#import "yourLoginViewController" //and add LoginViewControllerDelegate 

然後。我怎麼能隱藏它? – Kassem 2011-12-21 13:14:04

+1

@KassemBagher我用隱藏代碼編輯了我的答案,並鏈接到模態ViewControllers上的文檔。 – 2011-12-21 13:17:24

6

,我是爲我的應用程序之一的方法是隻需添加他們按正確的順序。將您的TabBar控制器添加到您的窗口,然後將登錄控制器添加到選項卡頂部。然後顯示你的窗口。除了您的登錄控制器外,用戶將看不到任何內容。一旦你登錄,你可以從視圖中刪除登錄控制器。

這種方式可能是最好的,如果你有你需要隱藏的信息,直到登錄。另一種方法是僅啓動登錄視圖。登錄成功後,取消登錄並添加標籤欄控制器。無論哪種方式都很好。

模態呈現可能是最簡單的,但需要在呈現之前提供一個視圖。所以如果登錄控制器下的數據和視圖不是那麼敏感的話,你可以考慮這個選項。

2

另一種方法是在你的appDelegate.h文件

在您的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]; 
} 
+1

不錯,最後一個答案是有效的,對我來說至少。 – RobCroll 2013-05-15 07:47:36

相關問題