ios - 将 presentModalViewController 与 Storyboard一起使用

标签 ios objective-c authentication storyboard presentmodalviewcontroller

我是 iOS 编程的新手,我正在开发一个 iPad 应用程序,该应用程序有一个标签栏 Controller ,上面附加了 4 个 View Controller (名为 FirstViewController、SecondViewController 等)。目前 Tab Bar Controller 被设置为应用程序的默认起点。我希望能够在用户到达那个点之前对用户进行身份验证,因此我添加了另一个名为 LoginViewController 的 View Controller ,它在 Storyboard 中自行 float 。

我想要做的是允许应用程序加载并在 didFinishLaunching 中显示登录页面,直到身份验证完成,然后关闭它。过去几天我一直在四处寻找,但我一直在尝试的一切都失败了。

我最近的尝试是

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];

UINavigationController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"];

loginVC.modalPresentationStyle = UIModalPresentationFullScreen;

[self.window.rootViewController presentModalViewController:loginVC animated:YES];

如有任何帮助,我们将不胜感激。它编译并运行,但 View 根本没有显示,我真的很困惑为什么会这样。

最佳答案

问题是我试图将它实例化为 UINavigationController,而实际上它只是一个 UIViewController。在 appDelegate.m 的 applicationDidBecomeActive 中调用它就可以了。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"];
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;    
[self.window.rootViewController presentModalViewController:loginVC animated:YES];

关于ios - 将 presentModalViewController 与 Storyboard一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9007186/

相关文章:

ios - 用于样式的 Objective-C 类别

authentication - 身份服务器如何在 API 或我们使用 Authorize 属性时验证 token ?

perl - Perl 中用于 Web 控制面板登录的唯一 Web 浏览器标识 ID

authentication - 如何在不使用桌面应用程序上的重定向 uri 的情况下使用 OAuth 2.0 在 SoundCloud 上进行身份验证?

ios - 如何从 iOS native 共享功能中删除某些选项?

ios - iOS 7 上的 MPNowPlayingInfoCenter AVPlayer

ios - 连接到 iOS 中需要用户名和密码的 JSON API

objective-c - NSScrollView 在 Cocoa 中不滚动且 contentView 大小不正确

ios - Swift:在没有 dequeueReusableCellWithIdentifier 的情况下创建静态自定义单元格

iphone - 动画后cocos2d自动删除 Sprite