Search code examples
iosswiftuiviewcontrollerseguetabbar

how to hide tab bar when push and show tab bar when back


I want

view controller 1: tab bar is showed

view controller 2: tab bar is showed

view controller 3: tab bar is not showed.

I wrote

// prepareForSegue in view controller 1, 
let upcoming = segue.destinationViewController as! viewcontroller3
upcoming.hidesBottomBarWhenPushed = true

// prepareForSegue in view controller 3,
let upcoming = segue.destinationViewController as! viewcontroller2
self.hidesBottomBarWhenPushed = true

When I go to view controller 3 from view controller 1, tab bar is not showed. Then, I go to view controller 2 from view controller 3, tab bar is showed. But when I tap back in view controller 2, tab bar is showed in view controller 3. self.hidesBottomBarWhenPushed = true does not make sense to me. But, I couldn't figure what I should do to fix that. Any suggestions? Thanks.

enter image description here


Solution

  • Edit: That solved the problem.

    It makes sense that the tab bar is appearing because when going clicking back from VC2 to VC3, nothing is telling VC3 to hide its Tab Bar.

    I think you have 2 solutions here (but haven't tested any):

    1. You can try doing something like this guy did. He added the hidesBottomBarWhenPushed logic in BackButtonPressed Handler.
    2. In VC3, do self.tabBarController?.tabBar.hidden = true in ViewDidLoad or viewWillAppear