0

我在应用程序中有一个登录屏幕视图和 5 个选项卡。我希望在完成 LoginScreen 后它应该移动到选项卡视图(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

4

3 回答 3

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

然后从您应用程序中的任何位置,您都可以执行以下操作:

[AppDelegate showTabs];

如果您在实施它时需要帮助,请告诉我。

于 2012-12-13T12:17:04.087 回答
1

您可以将您的UITabBarController作为您的初始视图。在那里您可以检查是否需要登录,或者是否自动登录。如果您需要转到登录屏幕,只需使用模态 segue 显示登录视图并在登录完成后将其关闭。

于 2012-12-13T10:24:54.040 回答
1

最初您将您的firstViewControlleras subView 添加到您的addDelegate.window,然后buttonClick您可以删除您的navController并添加tabBarControllerappDelegate.window

按照我的答案以获得更好的结果 链接

于 2012-12-13T14:04:58.323 回答