Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple NavigationLink in SwiftUI

Tags:

swiftui

Can you have multiple NavigationLinks in SwiftUI? The following only displays the first Link:

struct Test : View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: Text("First")) {
                Text("Visible")
            }
            NavigationLink(destination: Text("Second")) {
                Text("Invisible")
            }
            //EDIT: Also Invisible
            Text("Not rendered")
        }
    }
}

EDIT: Turns out everything under the first NavigationLink is not displayed

like image 328
Brandon Bradley Avatar asked Jan 27 '23 00:01

Brandon Bradley


1 Answers

Put your views inside a VStack:

struct Test : View {
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: Text("First")) {
                    Text("Visible")
                }

                NavigationLink(destination: Text("Second")) {
                    Text("Invisible")
                }
                //EDIT: Also Invisible
                Text("Not rendered")
            }
        }
    }
}
like image 161
kontiki Avatar answered Feb 16 '23 19:02

kontiki