[英]Change view with swiftUI
How can I change the view with swiftUI?如何使用 swiftUI 更改视图? This is my code:这是我的代码:
import SwiftUI
struct FirstView: View {
var body: some View {
Text("Click")
.onTapGesture {
print("clicked")
NextView()
}
}
}
struct NextView: View {
var body: some View {
Text("Next View")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
FirstView()
}
}
How can I view the "nextview" when clicking the text on the first view?单击第一个视图上的文本时如何查看“下一个视图”?
You should do the following:您应该执行以下操作:
import SwiftUI
struct FirstView: View {
var body: some View {
NavigationView {
NavigationLink(destination: NextView()) {
Text("Click")
.onTapGesture {
print("clicked")
}
}
}
}
}
struct NextView: View {
var body: some View {
Text("Next View")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
FirstView()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.