【发布时间】:2022-05-28 00:41:48
【问题描述】:
每次选择一行时,系统都会决定将随机索引转发到下一个视图。
下面是代码:
struct TestView: View {
let columns = [
GridItem(.flexible())
]
@State var showDetail = false
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(1...10, id: \.self) { index in
Text("\(index)")
.background(NavigationLink(destination: TestDetail(index: index), isActive: $showDetail) {
EmptyView()
}).onTapGesture {
showDetail = true
}
}
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
struct TestDetail: View {
var index: Int
var body: some View {
Text("\(index)")
}
}
【问题讨论】: