can you list the best methods for using navigationview and navigationlink in swiftui?

It seems you’re looking something like below (prepared & tested with Xcode 12.1 / iOS 14.1)

demo demo2

var body: some View {
    TabView(selection: $selection) {
         VStack {
            Text("Settings").font(.title)

            NavigationView {
                List(0..<players.count, id: \.self) { index in
                    NavigationLink(destination: DetailView2(player: players[index])) {
                        Text("\(index)")
                    }
                }
                     .navigationBarTitleDisplayMode(.inline)
                     .navigationBarHidden(true)
            }
        }
        .background(Color.white)
        .tabItem {
            Image(systemName: "house.fill")
            Text("Players")
        }
        .tag(0)
        
        VStack {
            Text("Settings").font(.title)
            List(0..<2, id: \.self) { index in
                Text("#\(index)")
            }
        }
        .tabItem {
            Image(systemName: "book.fill")
            Text("Foo")
        }
        .tag(1)
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top