How can I change the view with 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()
}
}
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.