2

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

1 Answer 1

2

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 !!
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.