Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swiftui

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

like image 819
Sorin Lica Avatar asked Jun 12 '19 07:06

Sorin Lica


1 Answers

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() 
}
like image 116
Alexander Jährling Avatar answered Oct 13 '22 22:10

Alexander Jährling