0

In this SwiftUI example, there is a TabView with 3 tabs. Tab A and tab C are always shown when the tab title is tapped. However clicking on tab B only shows the contents about 10% of the time. I'm using Xcode Version 14.3 (14E222b) and Swift 5. There are no errors or output in the console, and I don't know how to debug this. How can I debug this? Thank you

import SwiftUI

struct TabAContentView: View {
    var body: some View {
        NavigationView {
            VStack {
                List {
                    ForEach(1..<3) { item in
                        Text("A \(item)")
                    }
                }
            }
            .navigationTitle("Tab A")
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}

struct TabBContentView: View {
    var body: some View {
        NavigationView {
            VStack {
                List {
                    ForEach(1..<3) { item in
                        Text("B \(item)")
                    }
                }
            }
            .navigationTitle("Tab B")
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}

struct TabCContentView: View {
    var body: some View {
        NavigationView {
            VStack {
                List {
                    ForEach(1..<3) { item in
                        Text("C \(item)")
                    }
                }
            }
            .navigationTitle("Tab C")
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}

struct ContentView: View {
    var body: some View {
        TabView {
            TabAContentView()
            .tabItem {
                Text("tab A")
            }
            TabBContentView()
            .tabItem {
                Text("tab B")
            }
            TabCContentView()
            .tabItem {
                Text("tab C")
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}


@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
John Cashew
  • 1,078
  • 2
  • 12
  • 28

0 Answers0