In the app delegate you have the window var which is supposed to be the main application window:
self.window.rootViewController = anyViewController;
[self.window makeKeyAndVisible];
What you'll need to do is to decide what is the instance of anyViewController
. Normally you avoid 'flashing' by presenting the splash image, it is displayed until the key window get's visible with it's root view controller. Now what you can do is something like:
main.m
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
}
}
MyAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UserInfo * appUserInfo = [[DataManager sharedManager] applicationUserInfo];
UIViewController *anyViewController = [[ControllersManager sharedManager] launchViewControllerForUser:userInfo];
self.window.rootViewController = anyViewController;
[self.window makeKeyAndVisible];
return YES;
}
Where ControllersManager
is a singleton controller's manager which you'll want to use for all navigation operations. The method launchViewControllerForUser:
could be the following:
-(UIViewController*) launchViewControllerForUser:(UserInfo*) aUserInfo {
if (aUserInfo) {
return [[MainMenuViewController new] autorelease];
} else {
return [[LoginViewController new] autorelease];
}
}
And DataManager
is a singleton class which you'll use for all data operations such as read the previously saved application user wrapped in UserInfo
object.
Sometimes you do have a nib file for the main window, if you want to use such technique you'll need to customize the line
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
with the same pattern:
self.window = [[WindowManager sharedManager] keyLaunchApplicationWindow];
And inside this method you can also assign the root navigation controller. So you can actually combine this two approaches.
The main idea is to prepare the orchestrating managers to keep everything organized.