如何从CustomViewController中更改RootViewController(在AppDelegate中)?

时间:2011-07-13 07:52:06

标签: objective-c delegates uitabbarcontroller rootview

美好的一天,

我的应用程序具有在AppDelegate中加载的授权表单(SigninController),登录后(检查在SigninController.m中)TabBarController应该出现(作为应用程序的主视图)。

如何将控制器从Signin更改为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];
}    
}

1 个答案:

答案 0 :(得分:8)

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

[self.view removeFromSuperview];

appDelegate是应用程序共享委托。

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