1

I am trying to add a Navigation view that goes from my ContentView to my list items inside of my SectionView and then goes to my DetailView...i'm getting an error and i'm not sure why? im trying to nav link SelectionView( codeName: "Y")

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                
                NavigationLink("Y", destination:codeName.
                               (model:  .codeName))
                
                List (models) { model in
                    SelectionView(codeName: model.codeName)
                    
                }
                
            }
        }
        
        
#if DEBUG
        struct ContentView_Previews: PreviewProvider {
            static var previews: some View {
                ContentView()
                    .previewLayout(.device)
                    .preferredColorScheme(.dark)
                    .previewDevice("iPhone 13 Pro Max")
            }
        }
#endif
        
    }
}

aheze
  • 24,434
  • 8
  • 68
  • 125

1 Answers1

0

The destination also should be a view.

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach(0 ..< 5) { item in
                    
                    NavigationLink(
                        destination: Text("Destination \(item)"),
                        label: {
                            Text("Hello, world!  \(item)")
                                .padding()
                        })
                }
            }
        }
    }
}
YodagamaHeshan
  • 4,996
  • 2
  • 26
  • 36
  • Hi, So I was following a youtube video and they used a NavigationButton but I guess that has been depreciated. This was the code that he used – Wen Love Howard Sep 30 '21 at 09:40
  • NavigationView { List (developers){Developer in NavigationButton: (destination: ContentDetail (codeName: developer.codeName)) { Contentrow(codeName: developer .codeName) – Wen Love Howard Sep 30 '21 at 09:40
  • In my code, I changed the values from developer, to model. I changed the ContentDetail to DetailView, I changed the ContentRow to SectionView ....everything else has stayed the same but now I cant figure out how to use the NavigationLink rather than the Navigation Button that he used – Wen Love Howard Sep 30 '21 at 09:41
  • https://youtu.be/Pfw7zWxchQc?t=1060 This is the Video and im trying to do the same thing except with Navlink – Wen Love Howard Sep 30 '21 at 09:45
  • https://stackoverflow.com/questions/57615514/unresolved-identifier-navigationbutton-error – YodagamaHeshan Sep 30 '21 at 16:44
  • Instead I will suggest better tutorial , If you are gonna follow alone https://cs193p.sites.stanford.edu – YodagamaHeshan Sep 30 '21 at 16:46