【发布时间】:2020-04-12 18:03:33
【问题描述】:
我对@987654321@ 比较陌生。我想实现weatherList 的第一项以不同的视图显示。
不幸的是,我在这 2 行 (VStack and at ForEach-Line) 中收到此错误。如果我把if i == 0 收起来,然后只用于所有listitems 的正常布局,就没有错误。
ERROR: Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols
这是我的代码:
var body: some View {
NavigationView {
VStack { // here first error
if self.model.error != nil {
Text(self.model.error!)
}
ForEach(0..<self.model.weatherList.count, id: \.self) { i in // here second error
if i == 0 {
NavigationLink(destination: DetailView(model: self.model.weatherList[i])) {
RowView(model: self.model.weatherList[i])
}
}
else{
NavigationLink(destination: DetailView(model: self.model.weatherList[i])) {
RowView(model: self.model.weatherList[i])
}
}
}
}
.navigationBarTitle(Text("Weather in " + UserSettings.instance.locationSetting))
.navigationBarItems(trailing:
Button(action: {
self.model.reload()
}) {
Image(systemName: "arrow.clockwise")
}
.disabled(model.reloading)
)
}
}
不胜感激每一个建议。谢谢。
【问题讨论】: