Sunday, January 14, 2024
HomeiOS Developmentios - In SwiftUI, when the MyView popup sheet then dismissed, the...

ios – In SwiftUI, when the MyView popup sheet then dismissed, the MyView must be displayed as a substitute of ListView


Right here is three view,ContentView,ListView and MyView。Click on first backside icon present ListView,then click on NavigationLink show MyView.Click on the button show sheet,dismiss the sheet the ListView displayed on the display.


struct ContentView: View {
    var physique: some View {
        NavigationView {
            TabView {
                ListView().tabItem {
                        Label("checklist view", systemImage: "face.smiling")
                    }
                Textual content("checklist 2 content material").tabItem {
                    Label("textual content", systemImage: "face.smiling")
                }
            }
        }
    }
}

struct ListView: View {
    var physique: some View {
        ScrollView(.vertical, showsIndicators: false) {
            LazyHStack(alignment: .high) {
                LazyVStack {
                    NavigationLink(vacation spot: MyView()) {
                        Textual content("check")
                    }
                }
            }
        }
    }
}

struct MyView: View {
    @State non-public var isShowingSheet = false
    @Atmosphere(.presentationMode) var presentationMode
    var physique: some View {
        Button(motion: {
            isShowingSheet.toggle()
        }) {
            Textual content("Present Sheet")
        }
        .sheet(isPresented: $isShowingSheet,
               onDismiss: didDismiss)
        {
            VStack {
                Textual content("License Settlement")
                    .font(.title)
                    .padding(50)
                Textual content("""
                    Phrases and situations go right here.
                """)
                .padding(50)
                Button("Dismiss",
                       motion: { isShowingSheet.toggle() })
            }
        }
    }

    func didDismiss() {
        presentationMode.wrappedValue.dismiss()
    }
}

In MyView sheet dismissed,ought to show MyView



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments