【发布时间】:2020-09-08 19:23:31
【问题描述】:
我正在尝试在 swiftui 中创建一个网格视图,但它不适合我。有人可以告诉我我做错了什么吗?我尝试使用 c 样式的 for 循环,我可以在其中设置一个变量并递增它,但是当我这样做时 swiftui 会抛出一个错误。
struct ProductSubCat: View {
@State var productCategory = String()
@State var number = Int()
@ObservedObject var allData = WebserviceGetDataSolutions()
@State var theCount = 0
var body: some View {
ScrollView {
Spacer()
ForEach(0 ..< self.allData.posts[self.number].productLines.count / 2, id: \.self) {row in
HStack {
ForEach(0..<2) {cell in
NavigationLink(destination: ProductDetails())
{
Text(self.allData.posts[self.number].productLines[row].system)
Image("stonclad")
.resizable()
.aspectRatio(contentMode: .fit)
}.buttonStyle(PlainButtonStyle())
}
}
}
}
}
}
【问题讨论】:
-
请阅读并考虑stackoverflow.com/help/how-to-ask 和stackoverflow.com/help/minimal-reproducible-example,您应该(!)告诉我们出现了什么错误以及在哪一行...
-
示例代码实际可运行时会有很大帮助 - 请用简单的结构替换“WebserviceGetDataSolutions”之类的内容。
-
现在你可以在 wwdc2o2o 更新
swiftUI2.o后使用LazyHGrid和LazyVGrid... hackingwithswift.com/quick-start/swiftui/…
标签: ios swift xcode swiftui swift5