我有以下视图,我需要通过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")
}
}
但它给了我以下错误:
传递给不带参数的调用的参数
不传递任何变量:NavigationLink (destination: DetailsEvent ()
一切正常。
详情Event.swift
struct DetailsEvent: View {
var body: some View {
Text("here details content")
}
}
您的结构没有名为 item 的属性。你需要这样的东西:
struct DetailsEvent: View {
let item: Event
var body: some View {
Text("here details about \(item.title)")
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)