SwiftUI List with NavigationLink

Hi Team,

I have a List as below listing data from Core Data and it’s working well, however I wish to view the details of a row when the user taps on a Row… Taking them to another View called ListItem() which is within the NavigationLink…
However I am not sure what code I use to send to the new View using the NavigationLink.

See List below…

Any help would be appreciated… thank you !

List {
ForEach(entry, id: .id) { entry in
NavigationLink(destination: ListItem() ) {
VStack(alignment: .leading){
HStack{
Image(“my-two-stroke-white”)
.resizable()
.frame(width: 20.0, height: 20.0)
Text(entry.name ?? “Unknown”)
.fontWeight(.bold)
.foregroundColor(Color.blue)
}
HStack(alignment: .center){
Text(entry.ratio ?? “Unknown”)
.foregroundColor(Color.purple)
Text(“Mix Ratio”)
.foregroundColor(Color.purple)
}
Text(entry.comment ?? “Unknown”)
.foregroundColor(Color.gray)
.lineLimit(3)
}

        }
        .padding(.top, 15.0)
        
      }
      .onDelete(perform: removeEntry)
      
    }

Other View:

import SwiftUI

struct ListItem: View {

var body: some View {

Text(“Hello, World!”)

}

}

struct ListItem_Previews: PreviewProvider {

static var previews: some View {

ListItem()

}

}

Hey Craig,

Did you try following this tut here? It shows you how to go from an item in the list to a detail view
https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation#set-up-navigation-between-list-and-detail

1 Like

Hi Chris,

I have looked at that but are having trouble understanding it and implementing it into my code.

Is there a chance I could send you my project to see if you could help me ?

Cheers.

Craig.