Skip to main content
added 555 characters in body
Source Link
Sagar Chauhan
  • 5.8k
  • 2
  • 24
  • 58

AddTo fix your issue you need to bind and manage tag with NavigationLink in NavigationView with destination, So create one state inside you view class nameas follow, just add above body. See following

@State var selection: Int? = nil

Then update your button code: as follow to add NavigationLink

NavigationLink(destination: <DestinationView>Text("Test"), tag: 1, selection: $selection) {
    Button(action: {
    // your code  print("login tapped")
        self.selection = 1
    }) {
        HStack {
            Spacer()
            Text("Login").foregroundColor(Color.white).bold()
            Spacer()
        }
    }
    .accentColor(Color.black)
    .padding()
    .background(Color(UIColor.darkGray))
    .cornerRadius(4.0)
    .padding(Edge.Set.vertical, 20)
}

See more details here:Meaning is, when selection and https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation#set-up-navigation-between-list-and-detailNavigationLink tag value will match then navigation will be occurs.

I hope this will fix your issuehelp you.

Add NavigationLink in NavigationView with destination view class name. See following code:

NavigationLink(destination: <DestinationView>) { 
    // your code
}

See more details here: https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation#set-up-navigation-between-list-and-detail

I hope this will fix your issue.

To fix your issue you need to bind and manage tag with NavigationLink, So create one state inside you view as follow, just add above body.

@State var selection: Int? = nil

Then update your button code as follow to add NavigationLink

NavigationLink(destination: Text("Test"), tag: 1, selection: $selection) {
    Button(action: {
        print("login tapped")
        self.selection = 1
    }) {
        HStack {
            Spacer()
            Text("Login").foregroundColor(Color.white).bold()
            Spacer()
        }
    }
    .accentColor(Color.black)
    .padding()
    .background(Color(UIColor.darkGray))
    .cornerRadius(4.0)
    .padding(Edge.Set.vertical, 20)
}

Meaning is, when selection and NavigationLink tag value will match then navigation will be occurs.

I hope this will help you.

Source Link
Sagar Chauhan
  • 5.8k
  • 2
  • 24
  • 58

Add NavigationLink in NavigationView with destination view class name. See following code:

NavigationLink(destination: <DestinationView>) { 
    // your code
}

See more details here: https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation#set-up-navigation-between-list-and-detail

I hope this will fix your issue.