简体   繁体   中英

How to navigate views within an IF statement in SwiftUI

I need to be able to show a different view depending on IF statements but I am unable to figure it out:

Example:

if content == value1 {
     // go to view1
}
if content == value2 {
     // go to view2
}

You can use if/else, like this:

import SwiftUI

struct Test: View {
    @State private var something: Bool = false
    
    var body: some View {
        ZStack {
           if something {
               View1()
           } else {
               View2()
           }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM