ios - 呈现登录 UINavigationController 显示黑屏

标签 ios objective-c interface-builder

我的 iOS 应用程序需要用户身份验证,当用户未通过身份验证时,应用程序应显示一个用户可以登录的 ViewController。该屏幕还为用户提供了创建帐户的选项,因此整个登录屏幕(和可选的注册屏幕)都是使用以编程方式显示的 UINavigationController 进行设置的。

使用以下代码显示登录屏幕:

- (void)promptCredentials{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginScreenNav = [storyboard instantiateViewControllerWithIdentifier:@"LoginNavigationController"];
        [loginScreenNav setModalPresentationStyle:UIModalPresentationFullScreen];
        [self presentModalViewController:loginScreenNav animated:YES];
    });
}

但是,当调用此方法时,应用程序会导航到黑屏 enter image description here 。以编程方式向用户呈现不同 ViewController 的正确方法是什么?我发现了几个与此类黑屏相关的问题,但是,没有一个答案对我有用。我的应用程序在 iOS 8.2 上运行。

最佳答案

您需要创建一个 UIViewcontroller 并将其设置为您的 UINAvigationController 的根 Controller 。

presentModalViewController 从 ios6 开始被弃用,尝试使用 presentViewController。

UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginNavigationController"];

UINavigationController  *loginScreenNav = [[UINavigationController alloc] initWithRootViewController:vc];

[self presentViewController:loginScreenNav animated:YES];

关于ios - 呈现登录 UINavigationController 显示黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29328272/

相关文章:

ios - 在调整角度的同时根据图片计算梯形的面积

ios - 如何在弹出窗口内的 UITableView 内导航

ios - 使用 publish_stream 权限从 iOS 向页面发送帖子

interface-builder - 带有 OpenGL 3.2 核心的 NSOpenGLView

ios - Storyboard 导出的弱引用保留不明确的行为

cocoa - 界面生成器 - 使用布局 View 框

ios - NSAttributedString 对于自动调整异常无效

ios - NSURLSessionConfiguration 和 NSURLRequest 的相同属性?

objective-c - 在 Xcode 中制作另一个屏幕 (iOS)

java - 将 C++ 与 Objective-C 和 Java 混合使用