简体   繁体   English

iOS:在UITabbarController内部显示登录viewcontroller或“另一个” viewcontroller吗?

[英]iOS: Show login viewcontroller or “another” viewcontroller inside of UITabbarController?

I have a tabbar with 5 tabs. 我有一个带有5个标签的标签栏。
3 of these tabs requires authentication by having an account. 这些标签中的3个需要拥有帐户才能进行身份验证。 I know one solution is to present a modal viewcontroller when pressing one of these tabs. 我知道一种解决方案是在按下这些选项卡之一时显示一个模态视图控制器。

I wish to present the login viewcontroller inside of the tabs instead of showing it modally. 我希望在选项卡中显示登录ViewController,而不是模态显示。 How can this be done and how can I "reload" the tabbar with the other viewcontrollers once a user has logged in? 用户登录后,该如何完成?如何将“ tabbar”与其他ViewController“重新加载”?

I would do this by creating a subclass of UINavigationController which receives a UIViewController to show if user is logged in, and shows the login page in the other case. 我将通过创建UINavigationController的子类来实现此目的,该子类接收一个UIViewController来显示用户是否已登录,并在另一种情况下显示登录页面。

class CustomNavController:UINavigationViewController {
  let loggedInViewController:UIViewController
  init(loggedInVC:UIViewController) {
    loggedInViewController = loggedInVC
    if (userLoggedIn) {
      onLogin()
    } else {
      onLogout()
    }
    //setup listeners for authentication
    super.init()
  }
  onLogout () {
    self.viewControllers = [AuthenticationVC()]
  }
  onLogin () {
    self.viewControllers = [loggedInViewController]
  }
}


//code for setting up your UITabBarViewController
class MyTabbar:UITabBarViewController {
  init() {
    viewControllers = [
      FirstVC(), 
      SecondVC(),
      CustomNavController(ThirdVC()), 
      CustomNavController(ForthVC()), 
      CustomNavController(FifthVC())
    ]
  }
}

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

相关问题 通过UITabBarController中的Storyboard ID显示ViewController - Show viewcontroller by storyboard id inside UITabBarController 强制UITabBarController中的ViewController在iOS 7中变为横向 - Force ViewController in UITabBarController to be landscape in iOS 7 在UITabBarController内设置ViewController的标题 - setting the title of a ViewController inside a UITabBarController 如何在UITabBarController中显示ViewController? - How can I show ViewController in UITabBarController? 显示不在 UITabBarController 的 viewControllers 列表中的 ViewController - Show a ViewController that is not in UITabBarController's viewControllers list 从另一个viewController显示一个viewController,当它们都是UITabBarController的一部分时 - showing one viewController from another viewController, when both are part of a UITabBarController 显示另一个ViewController - Show another ViewController iOS ViewController调用容器内的子ViewController - ios viewcontroller to call child viewcontroller inside container 如何在另一个ViewController中将带有Xib的ViewController显示为SubView - How to show a ViewController with Xib in Another ViewController as a SubView IOS 5 - 从另一个ViewController调用ViewController - IOS 5 - Call a ViewController from another ViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM