Loading a different XIB file after Application launches in TabBar Application Template
I'm creating an app where user needs to login first and only after that they can view anything in the app. To achieve that, I have created a new XIB file with the name 'AuthView'.
I know开发者_运维百科 I need to put the code inside 'applicationDidfinishLaunching' method, but I don't know what code do I need to put inside it.
I'm developing the app using 'Tab Bar Application' template.
By default the end of the ApplicationDidFinishLaunchingWithOptions method looks like this:
[window addSubview:tabcontroller.view];
[window makeKeyAndVisible];
return YES;
Adding a viewController that appears over everything first is easy. First, add the viewController to your implementation (using the real name of your controller, obviously):
#import "InitialScreenViewController.h"
Then modify the end of your ApplicationDidFinishLaunchingWithOptions method by adding two lines as shown:
[window addSubview:tabcontroller.view];
initialScreenViewController = [[InitialScreenViewController alloc] init];
[window addSubview:initialScreenViewController.view];
[window makeKeyAndVisible];
return YES;
Once you've verified the login (or whatever you want to do with the initial screen) simply dismiss it within the initial screen viewController like this:
[self.parentViewController.view setHidden:YES];
This wil allow you to show it again later if need be, like if you add logout and re-login functionality.
As you're using the Tab bar application template, your UIApplicationDelegate file should have a UITabBarController ivar named tabBarController.
You'll need to remove this ivar (and also remove it from your mainWindow XIB file).
Once this is done, go back to applicationDidfinishLaunching method and add the authentificate view in the windows like this :
MyAuthentificateViewController * viewController = [[[MyAuthentificateViewController alloc]initWithNibName:@"XIBFilename" bundle:nil] autorelease];
[windows addSubview:myAuthentificateViewController.view]];
Better you show your authenticate view first. In another view, place your tabbar controller.
精彩评论