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

前端 未结 1 1484
滥情空心
滥情空心 2021-02-19 18:26

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:15

    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)
提交回复
热议问题