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))**
}
我有三个独立的NavigationLinks(用星号突出显示),有三个独立的目的地视图;点击任何一个链接都会弹出一个包含所有激活链接视图的堆栈(当setGoal为false时,只显示CategoryAdd视图,否则三个视图都会打开)。在目标视图中,我使用一个按钮来关闭。
我尝试更改语法(使用destination:或将视图放在链接的花括号中)。我想使用标签和选择,但它已被弃用。我在一个VStack里放了三个NavigationLinks,它们工作正常(只打开一个视图),所以我觉得这是一个bug,但我是Swift的新手,所以我不知道。
1条答案
按热度按时间xuo3flqw1#
NavigationStack使用了一种不同的NavigationLink,它接受一个值并有一个匹配的NavigationDestination,例如