How to navigate to another view in NavigationView without NavigationButton in SwiftUI?

前端 未结 1 970
[愿得一人]
[愿得一人] 2021-02-19 18:15

As the questions says I want to navigate to another view without NavigationButton, something like \"pushView\" and \"popView\" in UIkit

1条回答
  •  后悔当初
    2021-02-19 19:09

    I consider this more like a work-around for a limitation, but it worked for me:

    Add a boolean state variable which defines whether the link is active. E.g.:

    @State private var showLinkTarget = false
    

    Add an invisible NavigationLink like this:

    NavigationLink(destination: LinkTargetView(), isActive: self.$showLinkTarget ) {
       Spacer().fixedSize() 
    }
    

    0 讨论(0)
提交回复
热议问题