2011-07-13 39 views
3

好日子,如何從CustomViewController中更改RootViewController(在AppDelegate中)?

我的應用程序已被授權形式被裝載在AppDelegate中,並在簽名(檢查是在SigninController.m)後TabBarController應該出現(如應用程序的主視圖)(SigninController)。

我該如何改變控制器從登錄到TabBar和?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
SigninController *aSigninController = [[SigninController alloc] initWithNibName:@"SigninView" bundle:nil]; 
self.currentController = aSigninController; 
[aSigninController release]; 

self.window.rootViewController = self.currentController; 
[self.window makeKeyAndVisible]; 
return YES; 
} 

SigninController.m

- (IBAction)signinClick 
{ 
........ 
if (loginOK == YES) 
{   
     //This place is ready to send messages to show TabBar 
} else { 
    UIAlertView *alert = ...... 
    [alert show]; 
    [alert release]; 
}  
} 
+0

請標記您正在使用的編程語言。 –

回答

8
[appDelegate.window addSubview:appDelegate.tabbarController.view]; 

[self.view removeFromSuperview]; 

的appDelegate是應用程序共享委託。

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
+0

我要在SigninController的頭文件中添加#import「MyAppDelegate.h」嗎? – LIAL

+0

是的,你需要添加它... – makboney

+0

我正在使用'self.view.window.rootViewController = self.loadThisViewWhenDone'for加載我的標籤欄控制器,但當我試圖設置導航欄控制器停止工作!我不知道爲什麼,但使用你的代碼幫助:) – pulkitsinghal

相關問題