答案 0 :(得分:4)
那只是容器,您需要在其中添加一些内容,如果您只是尝试一些尝试,请尝试以下操作:
var body: some View {
NavigationView {
Text("Testing")
}
}
答案 1 :(得分:3)
您不能有空的NavigationView
。在里面添加一些东西。
struct ContentView: View {
var body: some View {
NavigationView {
Text("Text here")
}
}
}
答案 2 :(得分:0)
第一:添加新的SwiftUI视图(名称:MapView.swift,无需更改代码) 第二:添加新的SwiftUI视图(名称:SecondView.swift) 然后更改ContentView和SecondView:
a)ContentView.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
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
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()
}
}