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

标签 ios cocoa-touch

我有一个应用程序有一个登录导航 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/

相关文章:

ios - 需要保持点击状态以选择它

ios - 在Objective-C中需要声明哪些场景关键字 “volatile”?

swift - 如何更改 UITableView 部分边框?

ios - HitTest 位于 SuperView 边界外的 UIButton

ios - 这里映射iOS SDK : Change the colour of sublegs in a route

ios - 退出 iOS 中的嵌套 block 处理

ios - UICollectionViewCell。我想添加 2 个不同的图片单元格

ios - 是否可以从 View 的 NIB 设置 navigationitem.title?

objective-c - 如何使用 Objective C 创建 zip 文件?

iphone - 声明两个具有不同名称的属性将指向同一个变量