Short Introduction

I am kind of new in the field of app development using the iOS platform. Currently I'm in need of developing a multiview application for iPhone as well as iPad.

My Research

I've been doing some research on development of multiview applications, and have found that the general approach is to use one of the provided controllers as a root view controller (the UI tab bar controller and so on). Either that, or to write your own root view controller.

My Problem

The specific problem I'm battling right now is mostly concerning how to build up a more complex application which consists of:

-A log-in view (this is the very first view presented to the user upon opening the app) -The rest of the application which should be navigated using an UI tab bar controller)

What I've come up with right now is this idea:

Create a custom root view controller. This root view controller will first present the log-in view to the user (by adding the log-in view as a subview of itself). After log-in, it should change the subview to the UI tab bar controller.

The actual question

My question then is if this is an acceptable approach of doing it? Basically I would have a root view controller which switches between views by adding those views as subviews of it self.

I haven't been able to really find any article that discuss acceptable ways of doing it. And my concern with my current idea is that having a main root view controller which basically contains all views of the application and switches between them could quickly become messy?

Any input would be appriciated :)

Thanks in advance.

有帮助吗?

解决方案

I have been looking for similar pattern a while ago. From what I have found, I concluded that the best way to handle login screen is to inject it to main application window. So you are doing it in your UIApplicationDelegate class

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if ([self loginNeeded])
    {
        [self presentLoginScreen];
    }else
    {
        [self presentTabBarController];
    }

    [self.window makeKeyAndVisible];
    return YES;
}

And i.e. presentLoginScreen looks like this:

- (void)presentLoginScreen
{
    SMLoginViewController* loginVC=[[SMLoginViewController alloc] initWithNibName:@"SMLoginViewController" bundle:[NSBundle mainBundle]];
    [self.window setRootViewController:loginVC];
    [loginVC release];
}

Analogically, in [self presentTabBarController] I create UITabbarController containing actual application and then call [self.window setRootViewController:tabbarController];

This is useful, as you don't expand you view hierarchy unnecessary.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top