我是 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/