0

When I first open my app, I see the TabView in a view (the MainView) as expected, but after switching to a different view, based on a ModeController class I created (which really just holds a boolean value and is observable) and then coming back, it is no longer visible.

The ModeController a @StateObject in the ContentView:

@StateObject var modeController: ModeController = ModeController()

...and is injected into the view as an environmentObject, the runMode can change, but starts out as false:

        if self.modeController.runMode {
            RunView()
                .environmentObject(modeController)
        } else {
            
            MainView()
                .environmentObject(modeController)
        }

I have a TabView in the MainView which works fine when you start out with the runMode=false. When I press a button in one of the views and set runMode to true, RunView appears. In it there is a button setting runMode to false. When I do that I got back to the MainView but the TabView is gone.

There is nothing particularly interesting about the MainView:

    TabView(selection: $selectedTab) {
    
            FirstHomeView()
                .tabItem {
                    Label("First", systemImage: "list.bullet.clipboard.fill")
                }
                .tag("FirstTab")
            
            SecondHomeView()
                .tabItem {
                    Label("Second", systemImage: "star.circle.fill")
                }
                .tag("SecondTab")
            
        
            MoreHomeView()
                .tabItem {
                    Label("More", systemImage: "ellipsis")
                }
                .tag("MoreTab")

        }

I don't know why the TabView would no longer be visible.

lcj
  • 1,355
  • 16
  • 37

0 Answers0