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.