Go to a new view using SwiftUI

前端 未结 12 1877
走了就别回头了
走了就别回头了 2020-12-08 19:28

I\'ve got a basic view with a button using SwiftUI and I\'m trying to present a new screen/view when the button is tapped. How do I do this? Am I suppose to create a delegat

12条回答
  •  半阙折子戏
    2020-12-08 20:18

    if don't want to show the navigationView you can hide it in destination.

    struct ContentViewA : View {
        var body: some View {
            NavigationView {
                VStack {
                    Text("Hello World")
                    NavigationLink(destination: ContentViewB()) {
                        Text("Go To Next Step")
                    }
                }
            }
        }
    }
    
    
    
    struct ContentViewB : View {
            var body: some View {
                NavigationView {
                    VStack {
                        Text("Hello World B")
    
                    }.navigationBarTitle("")
                    .navigationBarHidden(true)
                }
            }
        }
    

    or if you want to hide it based on conditions you can use @State for changing the visibility.

提交回复
热议问题