Mar*_*rga 8 swiftui navigationlink swiftui-list
我有以下视图,我需要将item内容传递到另一个视图(DetailsEvent.swift),我正在使用NavigationLink. (我使用的是 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")
}
}
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误:
传递给不带参数的调用的参数
不传递任何变量:NavigationLink (destination: DetailsEvent ()一切正常。
详情Event.swift
struct DetailsEvent: View {
var body: some View {
Text("here details content")
}
}
Run Code Online (Sandbox Code Playgroud)
您的结构没有名为 item 的属性。你需要这样的东西:
struct DetailsEvent: View {
let item: Event
var body: some View {
Text("here details about \(item.title)")
}
}
Run Code Online (Sandbox Code Playgroud)