问题
I have a login screen view and 5 tabs in the app.I want when I done with the LoginScreen and it should move to the Tabs views(5) .for this once Login Task is done,I have to remove the view and add the another view controller of the tab..how to do this...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
like this way I moves to the login view...now how to remove after completion of login and move to the tab1,tab2,tab3,tab4,tab5
回答1:
Initially you add your firstViewController
as subView to your addDelegate.window
, then on buttonClick
you can remove your navController
and add tabBarController
to appDelegate.window
Follow my answer for better result Link
回答2:
You can create the following methods in you AppDelegate to switch between 2 navigation controllers.
+ (AppDelegate *)sharedDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
+ (void)showLogin {
AppDelegate *selfInstance = [self sharedDelegate];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.viewController];
selfInstance.window.rootViewController = nav;
}
+ (void)showTabs {
AppDelegate *selfInstance = [self sharedDelegate];
self.viewController2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.viewController2];
selfInstance.window.rootViewController = nav;
}
Your didFinishLaunchingWithOptions method should then look like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
if( isLoggedIn ){
[AppDelegate showLogin];
} else {
[AppDelegate showTabs];
}
return YES;
}
Then from anywhere in you app you can do:
[AppDelegate showTabs];
Let me know if you need help implementing it.
回答3:
You can make your UITabBarController
as your initial view. There you can check if you need to log-in, or if you auto log-in. If you need to go to the login screen, just use a modal segue to display the login view and dismiss it when login is done.
来源:https://stackoverflow.com/questions/13857676/didfinishloading-view-change