1
                NavigationStack {
                    TextField("Factor Name", text: $factName)
                        .textFieldStyle(.roundedBorder)
                        .padding()
                                    Picker("Factor Type:", selection: $factType, content: {
                                        Text("Numeric").tag("num")
                                        Text("Scale").tag("scale")
                                        Text("Yes / No").tag("yn")
                                       Text("Categorical").tag("cat")
                                    })
                    Spacer()
                    if factType == "scale" {
                        HStack {
                            Text("Scale: ")
                            TextField("Low", text: $scaleLow1)
                                .textFieldStyle(.roundedBorder)
                            Text(" to ")
                            TextField("High", text: $scaleHigh1)
                                .textFieldStyle(.roundedBorder)
                        }
                    }
                    else if factType == "cat" {
                       ** NavigationLink("Add categories: ", destination: CategoryAdd(catArray: $catArray))
                    }**
                    Toggle(isOn: $setGoal) {
                        Text("Set-Goal:")
                            .multilineTextAlignment(.center)
                    }
                    Spacer()
                    if setGoal {
                        if (factType == "num" || factType == "scale") {
                            Text("Successful day: ")
                            HStack {
                                Button("Exact") {
                                    numericButton = "exact"
                                }
                                .buttonStyle(.bordered)
                                Button("Range") {
                                    numericButton = "range"
                                }
                                .buttonStyle(.bordered)
                            }
                            if numericButton == "range"
                            {
                                TextField("Minimum", text: $successMin)
                                    .textFieldStyle(.roundedBorder)
                                TextField("Maximum", text: $successMax)
                                    .textFieldStyle(.roundedBorder)
                            }
                            if numericButton == "exact"
                            {
                                TextField("", text: $successExact)
                                    .textFieldStyle(.roundedBorder)
                            }
                        }
                        else if (factType == "cat")
                        {
                            **NavigationLink("Pick successful categories:", destination: CatGoalSelect(catArray: $catArray, successCats: $successCats, selected: [""]))**
                        }
                        else if (factType == "yn")
                        {
                            Picker("", selection: $successYN, content: {
                                Text("Yes")
                                Text("No")
                            })
                            .pickerStyle(SegmentedPickerStyle())
                        }
                        Spacer()
                        HStack {
                            Text("How often to succeed?")
                            Picker("", selection: $successFreq, content: {
                                  Text("Everyday").tag("Everyday")
                                  Text("Certain days of the week").tag("Certain days of the week")
                                  Text("Number of days per period").tag("Number of days per period")
                                  })
                        }
                        Spacer()
                        if successFreq == "Certain days of the week"
                        {
                           ** NavigationLink("Choose days of the week", destination: DoWGoalSelect(successDoW: $successDoW))**
                        }

I have three separate NavigationLinks (highlighted with asterisks) with three separate destination views; clicking on any link brings up a stack of all activated links' views (while setGoal is false only the CategoryAdd view is displayed - otherwise all three are opened). Within the destination view I use a button to dismiss.

I tried changing the syntax (using destination: or putting the view in the curly braces of the link). I wanted to use tag and selection but it's been deprecated. I put three NavigationLinks in a VStack and they worked correctly (opening only one view), so I feel like this is a bug, but I'm new to Swift, so I don't know.

1 Answer 1

0

NavigationStack uses a different kind of NavigationLink it's the one that takes a value and has a matching .navigationDestination, eg

NavigationStack {
    List(parks) { park in
        NavigationLink(park.name, value: park)
    }
    .navigationDestination(for: Park.self) { park in
        ParkDetails(park: park)
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Maybe you can show the exact implementation of this using my code and not a list because I tried using .navigationDestination and it did not work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.