我有一个具有主视图控制器(登录控制器)的应用程序。如果授权完成,我将向用户显示另一个控制器(tabBarController)。我是这样做的:
应用委托:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
LogInViewController *logInController = [[[LogInViewController alloc] init] autorelease];
_tabBarController = [[UITabBarController alloc] init] ;
SearchViewController *searchController = [[[SearchViewController alloc] init] autorelease];
CabinetViewController *cabinetController = [[[CabinetViewController alloc] init] autorelease];
HelpViewController *helpController = [[[HelpViewController alloc] init] autorelease];
CatalogViewController *catalogController = [[[CatalogViewController alloc] init] autorelease];
NSArray *controllerArray = [NSArray arrayWithObjects:cabinetController, catalogController, searchController, helpController, nil];
[_tabBarController setViewControllers:controllerArray];
//[navController setViewControllers:controllerArray];
[self.window setRootViewController:logInController];
[self.window makeKeyAndVisible];
return YES;
}
然后在按钮事件上我做了这个:
-(void)logInUser:(id)sender
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window setRootViewController:delegate.tabBarController];
[delegate.tabBarController setSelectedIndex:0];
[self.view removeFromSuperview];
}
如何以更有效的方式做这种事情???提前感谢大家。