繁体   English   中英

将登录显示为模式iOS?

[英]Presenting Login as modal iOS?

我有一个具有登录导航控制器和标签栏控制器的应用程序。 我已经将我的标签栏控制器设置为根控制器,但是我希望登录导航控制器显示为模式,以便我可以在登录时将其关闭,如果显示则完全不显示。 它正在读取正确的行,但是没有显示landingviewcontroller 当我运行该应用程序时,它会直接跳转到TabBarController。

我的代码如下:

我有一种方法可以检查您是否已登录我的应用程序委托,这就是我告诉它呈现登陆视图控制器(登录)的地方。 我从逐步了解到,它可以正确确定我尚未登录并在运行时转到以下代码行:

[self.window.rootViewController presentViewController:landingVC animated:YES completion:nil];

完整的应用程序委托:

#import "GFAppDelegate.h"
#import "GFCredentialStore.h"

@implementation GFAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    UIViewController *tabBarController = [storyboard instantiateInitialViewController];
    UIViewController *landingVC = [storyboard instantiateViewControllerWithIdentifier:@"LandingViewController"];

    GFCredentialStore *store = [[GFCredentialStore alloc] init];

    if (store.isLoggedIn) {
        self.window.rootViewController = tabBarController;
    } else {
        [self.window.rootViewController presentViewController:landingVC animated:YES completion:nil];
    }


    // Set root view controller and make windows visible

    [self.window makeKeyAndVisible];

    return YES;
}

我试图弄清楚这一点,但理解它写得不好可能会令人困惑。 谢谢你的帮助。

你需要做的是始终设置rootViewControllertabBarController ,但如果用户没有从它记录通话presentViewController。 像这样:

self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
if (!store.isLoggedIn) {
    [tabBarController presentViewController:landingVC animated:YES completion:nil];
}

尝试这个:

self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
if (store.isLoggedIn==false) {
    [tabBarController presentViewController:landingVC animated:YES completion:nil];
} 

您的问题是,当尝试从self.window.rootViewController呈现视图控制器时不存在,因此rootViewController == nil

我建议您不要将其呈现为模态(因为您没有从中呈现的控制器),而是将登录视图控制器设置为root。

self.window.rootViewController = landingVC;

但是,如果您打算在选项卡栏上方显示登录名,请在我的提示之前查看答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM