gpt4 book ai didi

ios - 将登录呈现为模态 iOS?

转载 作者:行者123 更新时间:2023-11-28 19:03:27 25 4
gpt4 key购买 nike

我有一个应用程序有一个登录导航 Controller 和一个标签栏 Controller 。我已将我的选项卡栏 Controller 设置为根 Controller ,但我希望登录导航 Controller 显示为模态,以便我可以在他们登录时将其关闭,如果登录则根本不显示它。它正在读取正确的行,但未能显示 landingviewcontroller。当我运行该应用程序时,它会直接跳转到 TabBarController。

我的代码如下:

我有一个方法可以检查您是否已登录到我的应用委托(delegate)中,这是我告诉它显示登陆 View Controller (登录)的地方。我通过单步执行知道它正确地确定我没有登录并在运行时转到这行代码:

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

完整的应用委托(delegate):

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

我已尽力阐明这一点,但我知道它可能因写得不好而令人困惑。谢谢你的帮助。

最佳答案

您需要做的是始终将 rootViewController 设置为 tabBarController,但如果用户未登录,则从中调用 presentViewController。类似的东西:

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

关于ios - 将登录呈现为模态 iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22733155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com