DidFinishLoading视图更改

时间:2012-12-13 10:19:39

标签: iphone ios uiview uitabbarcontroller uiwindow

我有一个登录屏幕视图和应用程序中的5个标签。我想在完成登录屏幕时它应该移动到标签视图(5)。为此,一旦登录任务完成,我必须删除视图并添加选项卡的另一个视图控制器..如何执行此操作...

 - (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;
}

就像这样我移动到登录视图...现在如何在登录完成后删除并转移到tab1,tab2,tab3,tab4,tab5

3 个答案:

答案 0 :(得分:2)

您可以在AppDelegate中创建以下方法,以在2个导航控制器之间切换。

+ (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;
}

您的didFinishLaunchingWithOptions方法应如下所示:

- (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;
}

然后你可以在app中的任何地方做到:

[AppDelegate showTabs];

如果您需要帮助,请与我们联系。

答案 1 :(得分:1)

您可以将UITabBarController作为初始视图。在那里,您可以检查是否需要登录,或者是否自动登录。如果您需要进入登录界面,只需使用模态segue显示登录视图,并在登录时将其关闭。

答案 2 :(得分:1)

最初,您将firstViewController作为子视图添加到addDelegate.window,然后在buttonClick上,您可以移除navController并将tabBarController添加到appDelegate.window }

按照我的回答获得更好的结果Link