SwiftUI - Is there a popViewController equivalent in SwiftUI?

后端 未结 13 2096
说谎
说谎 2020-12-12 20:18

I was playing around with SwiftUI and want to be able to come back to the previous view when tapping a button, the same we use popViewController inside a

13条回答
  •  天涯浪人
    2020-12-12 21:17

    Modify your BView struct as follows. The button will perform just as popViewController did in UIKit.

    struct BView: View {
        @Environment(\.presentationMode) var mode: Binding
        var body: some View {
            Button(action: { self.mode.wrappedValue.dismiss() })
            { Text("Come back to A") }
        }
    }
    

提交回复
热议问题