将presentModalViewController 与故事板结合使用
我对 iOS 编程相当陌生,我正在开发一个 iPad 应用程序,该应用程序有一个选项卡栏控制器,附有 4 个视图控制器(名为 FirstViewController、SecondViewController 等)。目前,选项卡栏控制器设置为应用程序的默认起点。我希望能够在用户到达该点之前对其进行身份验证,因此我添加了另一个名为 LoginViewController 的视图控制器,该控制器在 Storyboard 中自行浮动。
我想要做的是允许应用程序加载,并在 didFinishLaunching 中显示登录页面,直到身份验证完成,然后关闭它。这几天我一直在四处寻找,但我一直在尝试的一切都失败了。
我最近的尝试是
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"];
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentModalViewController:loginVC animated:YES];
任何帮助将不胜感激。它编译并运行,但视图根本没有显示,我真的很困惑为什么会发生这种情况。
I'm fairly new to iOS programming and I'm working on an iPad app that has a Tab Bar Controller with 4 View Controllers (named FirstViewController, SecondViewController, etc) attached to it. Currently the Tab Bar Controller is set to be the default starting point of the app. I want to be able to authenticate the user before they reach that point, so I've added another View Controller called LoginViewController that is floating by itself in the Storyboard.
What I want to do is allow the app to load and in didFinishLaunching, display the login page until authentication is complete, then dismiss it. I've been searching around for the past couple days, but everything I've been trying has failed.
My most current attempt was
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"];
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentModalViewController:loginVC animated:YES];
Any help would be appreciated. It compiles and runs, but the view is not showing up at all and I really confused as to why this is happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是我试图将它实例化为 UINavigationController,而实际上它只是一个 UIViewController。在 appDelegate.m 的 applicationDidBecomeActive 中调用它就可以了。
The problem was I was trying to instantiate it as a UINavigationController, when in fact it was just a UIViewController. Calling this in applicationDidBecomeActive in appDelegate.m did the trick.
您需要从当前显示的 viewController 调用“presentModalViewController”,而不是要显示的视图。可能是这样的:
You need to call "presentModalViewController" from the currently displayed viewController, not the view that is to be displayed. Likely, something like this:
在 Swift 2 中,现在是:
In Swift 2, this is now: