我希望能够使用 2 个箭头在视图之间导航,并指示用户在哪个页面上。
目前,页面指示器有些准确(当我加载到新页面时正确),但是我无法让导航链接在这个结构中工作。
该函数位于其自己的文件中,并在另一个视图中使用Foo(progress: Index)
var Index : Int = 1
struct PageCounter: View {
let progress: Int
init(progress: Int) {
self.progress = progress
}
var body: some View {
HStack {
Button(action: { if Index > 1 { Index -= 1 } } ) {
Image(systemName: "lessthan") }
Spacer()
ForEach(1 ..< 8) {value in
if value-1 < self.progress {
Image(systemName: "circle.fill")
} else {
Image(systemName: "circle")
}
}
Spacer()
NavigationLink(destination: getDestination()) {
Button(action: { if Index < 8 { Index += 1 } } ) {
Image(systemName: "greaterthan") } }
}
}
func getDestination() -> AnyView {
if index == 1 {
return AnyView(View1())
} else if Index == 2 {
return AnyView(View2())
} else if Index == 3 {
return AnyView(View3())
} else if Index == 4 {
return AnyView(View4())
} else {
return AnyView(MainPage())
}
}
}
我怎样才能让它正常工作?有没有比我目前尝试的更好的方法来实现它?
