3

Ive a problem with the new NavigationLink in my app, when i click in the button, change the page but return back immidiatly. Where I wrong?

NavigationLink(destination: TeamsModuleView(), tag: t.id, selection: self.$selection) {
    Button(action:  {
        self.selection = t.id //Is dynamic
        self.settings.fixtureId = t.fixtureId
        self.settings.teamHomeId = t.teams.teamHomeId
        self.settings.teamAwayId = t.teams.teamAwayId
        self.settings.teamHome = t.teams.teamHome
        self.settings.teamAway = t.teams.teamAway
    }) {
        HStack {
            Text("Go")
                .foregroundColor(Color.white)
        }
        .frame(minWidth: 0, maxWidth: .infinity)
        .padding(20)
        .background(Color.init(red: 0.80, green: 0.16, blue: 0.24))
        .cornerRadius(7)
    }
    .padding([.leading, .trailing], 30)
}

1 Answer 1

1

The NavigationLink is not supposed to contain a button, it is a button.

NavigationLinks must contain a destination and some sort of title. They can contain a bool binding if active or not. But no Buttons.

Everything your button action does needs to be done in other ways.

Some more code would be helpful to identify what you're trying to achieve so we can help with your code.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Lilfaen, thanks for reply, ok so it's possible call a function when i click on NavigationLink? now i've pass the variable via constructor in the new view and now work correctly.
@StefanoToppi it would be great if you could share -at least- the code of TeamModuleView. Without any code i'm really able to help you because i don't really know what you need.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.