【问题标题】:Reset tabBar.isHidden doesn't work in viewWillAppear重置 tabBar.isHidden 在 vi​​ewWillAppear 中不起作用
【发布时间】:2017-07-13 16:03:31
【问题描述】:

顺序是tabBarController->navigationController->viewController->viewController 我在第二个 viewController 中编写了以下代码。 当用户来到第二个viewController时,我想隐藏标签栏。

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    self.tabBarController?.tabBar.isHidden = true
}

当用户点击“取消”按钮时,我想回到主页面。

@IBAction func cancelAction(_ sender: Any) {
        // Depending on style of presentation (modal or push presentation), this view controller needs to be dismissed in two different ways.
        self.navigationController?.popToRootViewController(animated: true)
    }

回到第一个viewController后,我想让标签栏再次显示。

override func viewWillAppear(_ animated: Bool) {
   self.tabBarController?.tabBar.isHidden = false
}

但实际上,该选项卡根本不显示。页面突然抖动了一下。不知道为什么。

【问题讨论】:

    标签: ios swift xcode


    【解决方案1】:

    删除所有设置标签栏的代码,并在 XIB 或 Storyboard 中为 Second View Controller 尝试此选项:

    【讨论】:

    • 谢谢!有用。但为什么我的代码没有按预期工作?
    • 可能是你忘了调用:super.viewWillAppear(animated)。如果你忘记了它可能会导致非常讨厌的问题追查。
    猜你喜欢
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    相关资源
    最近更新 更多