NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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 Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.