Demonstration of whitespace problem
当我将NavigationView嵌套在NavigationView中时,大量的空格将后退按钮和新的导航栏标题分隔开。在设置SwiftUI视图方面我做错了什么?
import SwiftUI
struct Dashboard: View {
@EnvironmentObject var user: User
let courses = Course.exampleCourses()
var body: some View {
NavigationView {
List(courses) { course in
NavigationLink(destination: CourseView(course: course)) {
Text(course.name)
}
}.navigationBarTitle("Welcome, \(user.first)!")
}
}
}
import SwiftUI
struct CourseView: View {
// @ObservedObject allows us to update views whenever values in course change
@ObservedObject var course: Course
@EnvironmentObject var user: User
var body: some View {
NavigationView {
List {
NavigationLink(destination: WritingPromptView(prompt: "What is your course goal, \(user.first)?", explanationText: "This is the answer", textLocation: self.$course.goal)) {
Text("Course Goal")
}
NavigationLink(destination: NotepadView(parent: self.course)) {
Text("Notepad")
}
NavigationLink(destination: WritingPromptView(prompt: "<Reflection prompt goes here>", explanationText: "<How to reflect goes here>", textLocation: self.$course.reflection)) {
Text("Reflection")
}
}.navigationBarTitle(course.name)
}
}
}
答案 0 :(得分:0)
这是一个双导航栏。只需从CourseView中删除NavigationView。如果您具有CourseView的预览,则可能要在其中包装NavigationView。