[英]SwiftUI can't create navigationview
That's just container, you need some content inside, If you are just trying something out try following:那只是容器,你需要里面有一些内容,如果你只是尝试一些东西,请尝试以下操作:
var body: some View {
NavigationView {
Text("Testing")
}
}
You cannot have an empty NavigationView
.你不能有一个空的
NavigationView
。 Add something inside.在里面加点东西。
struct ContentView: View {
var body: some View {
NavigationView {
Text("Text here")
}
}
}
FIRST: Add new SwiftUI-View (Name: MapView.swift without code-changing ) SECOND: Add new SwiftUI-View (Name: SecondView.swift) THEN Change ContentView and SecondView:第一:添加新的 SwiftUI-View(名称:MapView.swift,无需更改代码)第二:添加新的 SwiftUI-View(名称:SecondView.swift),然后更改 ContentView 和 SecondView:
a) ContentView.swift a) 内容视图.swift
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
MapView() // on upper Screen will appear: "Hello World"
NavigationView {
NavigationLink(destination: SecondView()) {
VStack {
Text("click here")
.fontWeight(.heavy)
.font(.largeTitle)
.padding()
Text("go to screen II")
}
}
} //End of NavigationView
}// End of VStack
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
VStack {
ContentView()
}
}
}
b) SecondView.swift b)SecondView.swift
import SwiftUI
struct SecondView: View {
var body: some View {
VStack {
Text("Screen II")
.fontWeight(.heavy)
.foregroundColor(.blue)
.font(.largeTitle)
.padding()
Text("you changed it")
Text("GRATULATION!")
}
}
}
struct SecondView_Previews: PreviewProvider {
static var previews: some View {
SecondView()
}
}
c) MapView.swift c) 地图视图.swift
import SwiftUI
struct MapView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.