将ViewController放在TabBarController之上

时间:2011-09-07 10:16:00

标签: iphone objective-c ios uiviewcontroller uitabbarcontroller

基本上我想在展示我的TabBarController之前在我的iPhone应用程序中创建一个登录屏幕。我尝试了以下方法,首先在窗口子视图中添加我的TabBarController,然后在我的LoginViewController上添加。我做错了什么或者我应该完全不同?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];

    NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];

    DefaultViewController *dvc = [[DefaultViewController alloc] init];
    UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
    dvc_nc.tabBarItem.title = @"Home";
    //dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
    [tabItems addObject:dvc_nc];
    [dvc release];
    [dvc_nc release];

    OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
    ovc_nc.tabBarItem.title = @"Option";
    //ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Option" ofType:@"png"]];

    [tabItems addObject:ovc_nc];
    [ovc release];
    [ovc_nc release];

    UITabBarController *tbc = [[UITabBarController alloc] init];
    tbc.viewControllers = tabItems;
    self.tabController = tbc;
    [tabItems release];
    [tbc release];

    [self.window addSubview:self.tabController.view];

    LoginViewController *lvc = [[OptionsViewController alloc] init];
    UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
    [self.window addSubview:lvc_nc.view];
    [lvc release];
    [lvc_nc release];

    return YES;
}

2 个答案:

答案 0 :(得分:3)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];

    NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];

    DefaultViewController *dvc = [[DefaultViewController alloc] init];
    UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
    dvc_nc.tabBarItem.title = @"Home";
    //dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"]];
    [tabItems addObject:dvc_nc];
    [dvc release];
    [dvc_nc release];

    OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
    ovc_nc.tabBarItem.title = @"Option";
    //ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Option" ofType:@"png"]];

    [tabItems addObject:ovc_nc];
    [ovc release];
    [ovc_nc release];

    UITabBarController *tbc = [[UITabBarController alloc] init];
    tbc.viewControllers = tabItems;
    self.tabController = tbc;
    [tabItems release];
    [tbc release];

    [self.window addSubview:self.tabController.view];

    LoginViewController *lvc = [[OptionsViewController alloc] init];
    UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
[self.tabController presentModalViewController:lvc_nc animated:no];
    [lvc release];
    [lvc_nc release];

    return YES;
}

答案 1 :(得分:0)

我会使用两种不同的观点。一个将处理登录过程,一个是您的“登录视图”,它提供您的应用程序的功能。当您的应用启动时,您添加登录视图,检查用户名/密码,当登录正常时,​​您切换到第二个视图。