ios - presentViewController 从 TabBarController 到外面

标签 ios storyboard uitabbarcontroller

这是我的主要 Storyboard:

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/

相关文章:

swift - 使导航栏透明后如何将其更改回半透明

ios - Swift iOS UITabBar 自定义

IOS - UIViewController 不会旋转

iphone - 禁用点击当前选项卡(UITabBarController)iPhone App

iOS AFNetworking 响应序列化器 : Many serializers for each response, 或一个序列化器来统治它们?

ios - Unity3d - 在 iOS 上构建时对象变得不可见

iphone - 确定 segue 是否为 unwind segue?

iphone - 每次选择选项卡时如何获得相同的 View ?

ios - 从 NSArray 中获取最后 10 个对象

ios - 以编程方式定位按钮,结果出乎意料