【问题标题】:How can I switch root UITabbar from anywhere in app?如何从应用程序中的任何位置切换根 UITabbar?
【发布时间】:2021-09-24 07:23:08
【问题描述】:

目前,我有一个主要的uitabbar(根视图),其中有 5 个选项卡。如果我想触发uitabbar 从应用程序中的任何位置切换选项卡。我该怎么做?

谢谢。

【问题讨论】:

  • 您可以在不更改 rootviewcontroller 的情况下全屏使用present。也使用导航控制器推送。不要玩 rootviewcontroller 仅在注销应用程序时使用它。

标签: ios swift uitabbar


【解决方案1】:

如果您在UIViewController 中,您可以通过以下方式访问UITabBarController

self.tabBarController

这将返回层次结构中最近的UITabBarController,如果没有则返回nil

【讨论】:

    【解决方案2】:

    您需要获取标签栏控制器的引用并执行类似的操作(在 UIViewController 内部提供)。如果您有自定义 UITabBarController 类,请将 as? UITabBarController 替换为 as? YourClass

    if let tabBarController = self.tabBarController as? UITabBarController {
        tabBarController.selectedIndex = 1
    }
    

    【讨论】:

      猜你喜欢
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 2019-05-01
      • 2016-07-25
      • 2012-05-11
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      相关资源
      最近更新 更多