【问题标题】:Show a ViewController that is not in UITabBarController's viewControllers list显示不在 UITabBarController 的 viewControllers 列表中的 ViewController
【发布时间】:2021-03-01 17:09:50
【问题描述】:

我有一个 UITabBarController,我正在将一些 ViewControllers 设置到它的 viewControllers 列表中,如下所示

let tabBar = UITabBarController();
tabBar.viewControllers = vcs;

当视图被加载时,vcs 列表中的第一个 ViewController 将被显示。 我想要的是显示一个不在vcs 列表中的 UIViewController(并且必须选择任何 tabBar)。 我只想在第一次加载视图时显示这个 UIViewController。之后,用户点击了其中一个 tabBarItems,我想加载关联的 ViewController。 所以我的问题是“显示一个 UIViewController”,它不在 vcs 列表中

【问题讨论】:

    标签: ios swift iphone


    【解决方案1】:

    UITabBarControllerDelegate方法tabBarController(_:shouldSelect:)

    让自己成为 UITabBarController 的代表,这取决于您是否使用 Storyboard,创建一个从 UITabBarController 继承的自定义类本身是 delegate 并将该类设置到 Storyboard 中可能会更容易。

    var hasNotShownYet = false
    
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        guard hasNotShownYet else { return true /* Allow selection as "normal" */ }
        presentCustomVCModally()
        hasNotShowYet = true
        return false
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 2015-10-20
      相关资源
      最近更新 更多