Pass information to another view with NavigationLink
Asked Answered
C

1

8

I have following View and I need to pass item content to another View (DetailsEvent.swift), I am using NavigationLink . (I'm using Xcode 11 GM)

struct Events: View {

    @ObservedObject var networkManager = NetworkManager()

    var body: some View {

        NavigationView{

            List(self.networkManager.eventos.events){ item in

                NavigationLink(destination: DetailsEvent(item: item))  {

                    VStack(alignment: .leading) {

                      HStack {

                        Image(systemName: "calendar")
                        .foregroundColor(.gray)

                        Text(item.start_date)
                            .font(.subheadline)
                            .foregroundColor(.gray)
                      }

                    Text(item.title)
                        .font(.headline)                    
                }
              }

           }
            .navigationBarTitle("Events")
        }
    }

But it gives me the following error:

Argument passed to call that takes no arguments

Without passing any variable: NavigationLink (destination: DetailsEvent () everything works fine.

DetailsEvent.swift

struct DetailsEvent: View {
    var body: some View {
        Text("here details content")
    }
}

error

Calpac answered 11/9, 2019 at 21:2 Comment(1)
added information (at the moment it is an empty view)Calpac
K
6

Your struct has no property called item. You need something like this:

struct DetailsEvent: View {

    let item: Event

    var body: some View {
        Text("here details about \(item.title)")
    }
}
Kilah answered 11/9, 2019 at 21:11 Comment(1)
Thanks, it worked for me. Declaring the variable in the destination view now works correctly for me.Calpac

© 2022 - 2024 — McMap. All rights reserved.