WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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,

   

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)
    }
}

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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

Reply to this topic…

You need to create an account or log in to reply.

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.