2

I'm implementing TabbedView using SwiftUI framework by referring https://developer.apple.com/documentation/swiftui/tabview

When running on the simulator, only the first tab view contents showing and other tabs contents not showing. Even after restarting XCode, simulator etc.

App video link: https://youtu.be/Gibu8jfQQ5I

struct ContentView : View {
    var body: some View {
         TabbedView {
            Text("The First Tab")
                .tabItem {
                    Image(systemName: "1.square.fill")
                    Text("First")
            }
            Text("Another Tab")
                .tabItem {
                    Image(systemName: "2.square.fill")
                    Text("Second")
            }
            Text("The Last Tab")
                .tabItem {
                    Image(systemName: "3.square.fill")
                    Text("Third")
            }
        }.font(.headline)
    }
}

Appreciate you help and suggestions!

Harshal Wani
  • 2,249
  • 2
  • 26
  • 41

1 Answers1

1

In beta 5, your code works, and also TabbedView was renamed to TabView. If you cannot upgrade to beta 5 yet, to fix your problem in beta 4, you need to add .tag(n) to each view:

struct ContentView : View {
    var body: some View {
         TabbedView {
            Text("The First Tab").tag(1)
                .tabItem {
                    Image(systemName: "1.square.fill")
                    Text("First")
            }
            Text("Another Tab").tag(2)
                .tabItem {
                    Image(systemName: "2.square.fill")
                    Text("Second")
            }
            Text("The Last Tab").tag(3)
                .tabItem {
                    Image(systemName: "3.square.fill")
                    Text("Third")
            }
        }.font(.headline)
    }
}
kontiki
  • 37,663
  • 13
  • 111
  • 125
  • Unfortunately this doesn't show the tabs under the "more" tab. So tabs 5, 6, 7, etc. Looks like a bug to me. – Thomas Vos Aug 05 '19 at 21:52