【发布时间】:2019-11-17 21:52:02
【问题描述】:
因此,由于某种原因,当我尝试在 ForEach 中引用变量时,它给了我以下错误:无法推断通用参数“数据”,明确指定通用参数来解决此问题”
我真的不知道为什么会抛出错误,这对我来说似乎很简单,但我卡住了
struct OptionsScrollView: View {
@State var scrollOptions = [
"test1",
"test2",
"test3"
]
@State var optionHeight = 50
var body: some View {
GeometryReader{outerGeo in
ScrollView{
VStack{
ForEach(self.scrollOptions.indices) {i in
GeometryReader {optionGeo in
Text( self.scrollOptions[i] )
} // end optionGeo
.frame(width: 100, height: self.optionHeight)
// ^^^^^^^^^^^^^^^^^
// adding this gives me the error
} // end ForEach
} // end VStack
} // end ScrollView
} // end outerGeo
}
}
【问题讨论】:
标签: swiftui