I am trying to change the view from the first view to final view in the code below in SWIFTUI. I would expect to go to final page after clicking button C. This does not happen unless I click C then A or B. What am I doing wrong?
struct ContentView: View {
@State private var c = false
@State private var a_or_b: letter?
enum letter {
case a; case b
}
var body: some View {
if c == true {
FinalView(c: $c)
} else {
VStack {
Text("First View")
Button(action: {
a_or_b = .a
}) {
Text("A")
}
Button(action: {
a_or_b = .b
}) {
Text("B")
}
Button(action: {
c = true
}) {
Text("C")
}
}
}
}
struct FinalView: View {
@Binding var c: Bool
var body: some View {
Text("Second View!")
}
}
It may a problem for @State update
You can just change like this: