WWDC22 SALE: Save 50% 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 Fernando Olivares

SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!

Read the book

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.