Reputation: 1662
Here is my code:
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()
}
}
When I tap on the CourseView I want it to show ContentView()
but it doesn't work.
I don't know why.
Can anyone help me
Upvotes: 2
Views: 1503
Reputation: 257693
It can be only one sheet in body, so
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 !!
}
Upvotes: 2