Ios 将presentModalViewController与情节提要一起使用
我对iOS编程相当陌生,我正在开发一款iPad应用程序,它有一个带有4个视图控制器(名为FirstViewController、SecondViewController等)的选项卡栏控制器。当前,选项卡栏控制器设置为应用程序的默认起点。我希望能够在用户到达该点之前对其进行身份验证,因此我添加了另一个名为LoginViewController的视图控制器,该控制器在情节提要中自动浮动 我想做的是允许应用程序加载,并在didFinishLaunching中显示登录页面,直到验证完成,然后将其关闭。在过去的几天里,我一直在四处寻找,但我所尝试的一切都失败了 我最近的尝试是Ios 将presentModalViewController与情节提要一起使用,ios,objective-c,authentication,storyboard,presentmodalviewcontroller,Ios,Objective C,Authentication,Storyboard,Presentmodalviewcontroller,我对iOS编程相当陌生,我正在开发一款iPad应用程序,它有一个带有4个视图控制器(名为FirstViewController、SecondViewController等)的选项卡栏控制器。当前,选项卡栏控制器设置为应用程序的默认起点。我希望能够在用户到达该点之前对其进行身份验证,因此我添加了另一个名为LoginViewController的视图控制器,该控制器在情节提要中自动浮动 我想做的是允许应用程序加载,并在didFinishLaunching中显示登录页面,直到验证完成,然后将其关闭。在
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"];
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentModalViewController:loginVC animated:YES];
任何帮助都将不胜感激。它编译并运行,但视图根本没有显示,我真的很困惑为什么会发生这种情况。您需要从当前显示的viewController调用“presentModalViewController”,而不是要显示的视图。可能是这样的:
[self.window.rootViewController presentModalViewController:loginVC animated:YES];
问题是我试图将其实例化为UINavigationController,而实际上它只是一个UIViewController。在appDelegate.m中的applicationIDbecomeactive中调用此函数就成功了
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"];
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentModalViewController:loginVC animated:YES];
在Swift 2中,现在是:
if let loginController: LoginViewController = mainStoryboard.instantiateViewControllerWithIdentifier("StoryboardControllerID") as? LoginViewController {
loginController.modalPresentationStyle = .FullScreen
self.window?.rootViewController?.presentViewController(loginController, animated: true, completion: { () -> Void in
// do stuff!
})
}