简体   繁体   English

从单个UITabBarItem有条件地产生两个不同的视图控制器

[英]Conditionally Produce two different view controllers from single UITabBarItem

I'm writing an iOS application that includes a UITabBarController, where one of the tabs is the user's profile. 我正在编写一个包含UITabBarController的iOS应用程序,其中的一个选项卡是用户的个人资料。 However, if the user is not signed in, I would like the application to display a different ViewController (Sign in/Sign up) instead. 但是,如果用户未登录,我希望应用程序显示其他ViewController(登录/注册)。

I currently have the profile tab routing to a navigaion controller which has its RootViewController as ProfileViewController. 我目前有配置文件选项卡路由到navigaion控制器,该控制器的RootViewController为ProfileViewController。 In ProfileViewController's viewDidLoad, I have a check to see if the user is signed in. If the user is not, It performs a segue to SignInSignUpViewController which eventually loops back to ProfileViewController. 在ProfileViewController的viewDidLoad中,我进行检查以查看用户是否已登录。如果用户未登录,它将对SignInSignUpViewController进行选择,并最终循环回到ProfileViewController。

This approach is over-complicated and broken in a couple ways. 这种方法过于复杂,有两种破损方式。 For example, the navigation controller allows for the user to back into the signup/signin view controller after they've already signed in. 例如,导航控制器允许用户在已经登录后返回到注册/登录视图控制器。

I feel like this is a pretty common idiom in iOS, but I can't find a good solution online. 我觉得这是iOS中很常见的习惯用法,但是我找不到在线的好解决方案。 Anyone have any ideas? 有人有想法么?

Thanks in advance! 提前致谢!

You might want to take a look at the UINavigationController method – setViewControllers:animated: . 您可能需要看一下UINavigationController方法– setViewControllers:animated: After you've logged in call this and pass your profile ProfileViewController. 登录后,调用它并传递您的配置文件ProfileViewController。 It will then be at the top of the stack, so the user won't be able to navigate back to the login view controller. 然后它将位于堆栈的顶部,因此用户将无法导航回登录视图控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM