【问题标题】:Removing large amounts of whitespace in a SwiftUI subview删除 SwiftUI 子视图中的大量空白
【发布时间】:2020-02-17 22:39:32
【问题描述】:

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)
        }
    }
}

【问题讨论】:

    标签: swift xcode swiftui xcode11


    【解决方案1】:

    这是一个双导航栏。只需从 CourseView 中删除 NavigationView。如果您有 CourseView 的预览,您可能希望将 NavigationView 包装在那里。

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-09
      相关资源
      最近更新 更多