这是我的代码:
import SwiftUI
struct HomeList: View {
@State private var show: Bool = false
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(0 ..< 5) { item in
CourseView()
.onTapGesture {
self.show.toggle()
}
.sheet(isPresented: self.$show) {ContentView()}
}
}
}
}
}
struct HomeList_Previews: PreviewProvider {
static var previews: some View {
HomeList()
}
}
当我点击CourseView时,我希望它显示ContentView()
,但是它不起作用。
我不知道为什么。
谁能帮我
答案 0 :(得分:0)
它只能是一张床单,所以
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(0 ..< 5) { item in
CourseView()
.onTapGesture {
self.show.toggle()
}
}
}
}
.sheet(isPresented: self.$show) {ContentView()} // move it here !!
}