这是我的主要 Storyboard:
如您所见,有一个主 TabBarController,但为了看到 TabBarController,用户必须先登录(位于主 TabBarController 之外的 LoginViewController,这是我在 TabBar 中所有 Controller 的 viewDidLoad 中的代码:
if ( ![Client isLoggedIn] ) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:Nil];
UIViewController* loginView = [storyboard instantiateViewControllerWithIdentifier:@"LoginScene"];
[self.navigationController presentViewController:loginView animated:YES completion:nil];
return;
}
但有时(!)这根本不起作用并且应用程序挂起(当它发生时甚至卸载应用程序也无济于事)
在这种情况下,将用户从 TabBarController 重定向到另一个 ViewController (LoginViewController) 的正确方法是什么,它不是 TabBarController 的子级?
最佳答案
您可以将单独的 NavigationViewController
作为 manual modal segue
连接到 TabbarController
。
为segue设置一个identifier
,然后你可以使用这个代码:
if ( ![Client isLoggedIn] ) {
[self performSegueWithIdentifier:@"MyModalSegue" sender:self];
}
这应该可以正常工作。此外,您还可以免费获得模态动画。
关于ios - presentViewController 从 TabBarController 到外面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22271945/