UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Can't dismiss sheet

Forums > SwiftUI

I have let say view A that is a sheet. From view A you can pull up another sheet, call it sheet B. I can dismiss sheet B just fine. But when I then try to dismiss sheet A. It wont dismiss. Does anyone else have this issue, if so how do you solve it.

Just for info, Sheet A is showing an edit contact view. From that view their is a VStack with a button in it that displays customs events. When you tap the button on the VStack it brings up sheet B. As I said I can dismiss that view just fine after creating the event. But sheet A will not dismiss.

I hope that is clear on what I is going on. I just cant understand why sheet A wont dismiss if I add event and then dismiss sheet B.

Thanks,

2      

Let's say, instead of describing View A and hiz friend View B, you just show some code. This would help us see what concepts you've mastered and where you might be having a little trouble.

Here's some code showing a simple HomeView. Tap the button and SheetOneView slides in as a sheet. On SheetOneView is another button that slides in SheetTwoView.

If you swipe down on SheetTwoView, you're back to SheetOneView. Again, swipe down and you're back to the HomeView.

//  Multi_Sheet_Experiment
//
//  Created by Obelix on 4/19/22.
import SwiftUI

struct HomeView: View {
    @State private var showSheet1 = false  // Toggle Sheet One
    var body: some View {
        VStack {
            Text("Home View").font(.largeTitle).foregroundColor(.cyan).bold().padding()
            Button { showSheet1.toggle() }
                label: { Text(showSheet1 ? "Hide Sheet 1" : "Show Sheet 1") }
        }.sheet(isPresented: $showSheet1) { SheetOneView() }
    }
}

struct SheetOneView : View {
    @State private var showSheet2 = false
    var body: some View {
        VStack {
            Text("Sheet One").font(.largeTitle).foregroundColor(.blue).bold().padding()
            Button { showSheet2.toggle() }
                label: { Text(showSheet2 ? "Hide Sheet 2" : "Show Sheet 2") }
        }.sheet(isPresented: $showSheet2) { SheetTwoView() }
    }
}

struct SheetTwoView : View {
    var body: some View {
        Text("Sheet 2").font(.largeTitle).foregroundColor(.indigo).bold().padding()
        Text("(Swipe down to dimiss.)").font(.caption)
    }
}

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.