BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

NavigationView scrolling broken when using TabView

Forums > SwiftUI

Hi all,

With the below code I get a very weird scrolling behaviour in my TabViews, LoginView is called on app launch:

struct LoginView: View {
    @State private var presentContent = false

    var body: some View {

        return NavigationView {
            ZStack{
                NavigationLink(
                    destination: ContentView(),
                    isActive: $presentContent,
                    label: {
                        EmptyView()
                    })

                Button("TEst") {
                    self.presentContent.toggle()
                }
            }

        }
    }
}

struct ContentView: View {
    var body: some View {
        TabView{
            Group{
                List{
                    Text("Item 1")
                    Text("Item 2")
                    Text("Item 3")
                }
            }
            .navigationTitle("Transactions")
            .tabItem {
                Image(systemName: "list.dash")
                Text("Transactions")
            }
            Group{
                List{
                    Text("Item 11")
                    Text("Item 12")
                    Text("Item 13")
                }
            }
            .navigationTitle("Summary")
            .tabItem {
                Image(systemName: "list.dash")
                Text("Summary")
            }
        }
    }
}

Any ideas what that might cause?

   

Sounds trite, but your code compiles and looks fine to me.

"Works for me!"

I am running Simulator with iOS 15.4 on iPhone 8 Plus. What iOS are you running in the simulator?

Please note: The Navigation TItle does not change for me. Once running, the app always shows Transactions above the lists. I never see a title named Summary.

   

Simulator: iPhone 8+ on 15.2 real device: iPhone 8+ on 15.4.1

both behave the same and show the issue

Have you tried jumping between the tabs and scrolling up and down again?

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.