SwiftUI - Is there a popViewController equivalent in SwiftUI?

后端 未结 13 2100
说谎
说谎 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条回答
  •  -上瘾入骨i
    2020-12-12 21:02

    You can also do it with .sheet

    .navigationBarItems(trailing: Button(action: {
                self.presentingEditView.toggle()
            }) {
                Image(systemName: "square.and.pencil")
            }.sheet(isPresented: $presentingEditView) {
                EditItemView()
            })
    

    In my case I use it from a right navigation bar item, then you have to create the view (EditItemView() in my case) that you are going to display in that modal view.

    https://developer.apple.com/documentation/swiftui/view/sheet(ispresented:ondismiss:content:)

提交回复
热议问题