【问题标题】:How to hide one tab in tab bar controller?如何在标签栏控制器中隐藏一个标签?
【发布时间】:2018-12-13 08:44:21
【问题描述】:

我正在使用 Xcode 10.1 和 Swift 4.2.1。我有这样的标签栏应用程序:

出于某些原因,我想隐藏/删除其中一个栏以接收如下内容:

那么,问题来了:如何隐藏Tab Bar的一个Tab? 要指定:按下某个按钮,隐藏一个选项卡。再按一次,Tab 再次出现。

【问题讨论】:

    标签: swift xcode uitabbarcontroller uitabbar uitabbaritem


    【解决方案1】:

    删除:

    tabBarController?.viewControllers?.remove(at: index)
    

    添加回来:

    tabBarController?.viewControllers?.insert(newElement: viewController, at: index)
    

    【讨论】:

    • 非常感谢!它运行良好:快速、无崩溃,您甚至可以隐藏自己的视图!但是我可以稍微扩展一下我的问题吗?如何从 AppDelegate 做这个技巧?
    • let window = UIWindow(frame: UIScreen.main.bounds) let tabBarController = window?.rootViewController as! UITabBarController
    • 感谢您的回答!但是在方法 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 它会导致崩溃。
    • 最好这样做: if let rootViewController = window?.rootViewController as? UITabBarController { rootViewController.viewControllers?.remove(at: 0) }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    相关资源
    最近更新 更多