gpt4 book ai didi

swift - 删除 SwiftUI subview 中的大量空白

转载 作者:行者123 更新时间:2023-11-30 10:33:55 26 4
gpt4 key购买 nike

Demonstration of whitespace problem

当我将 NavigationView 嵌套在 NavigationView 中时,后退按钮和新的导航栏标题之间​​会出现大量空白。我在设置 SwiftUI View 时做错了什么吗?

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

最佳答案

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

关于swift - 删除 SwiftUI subview 中的大量空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58493091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com