为什么导航 link/view 没有出现在工具栏上?
Why doesn't navigation link/view appear on the toolbar?
这是我的代码
var body: some View {
Form {
Section(header: Text("People")) {
ForEach(people) { person in
PersonListItem(data: .constant(person))
}
}
}.listStyle(InsetListStyle())
.toolbar {
NavigationLink(destination: NewPerson(personData: .constant(Person.empty))){
Image(systemName: "plus")
}
}
}
在 运行 上显示“人物”部分及其内容。但不在工具栏上显示加号。我错过了什么?
用 NavigationView
包裹了你的表格
struct ContentView: View {
var body: some View {
NavigationView{ // Here
Form {
Section(header: Text("People")) {
ForEach(people) { person in
PersonListItem(data: .constant(person))
}
}
}.listStyle(InsetListStyle())
.toolbar {
NavigationLink(destination: NewPerson(personData: .constant(Person.empty))){
Image(systemName: "plus")
}
}.navigationBarTitleDisplayMode(.inline)
}
}
}
这是我的代码
var body: some View {
Form {
Section(header: Text("People")) {
ForEach(people) { person in
PersonListItem(data: .constant(person))
}
}
}.listStyle(InsetListStyle())
.toolbar {
NavigationLink(destination: NewPerson(personData: .constant(Person.empty))){
Image(systemName: "plus")
}
}
}
在 运行 上显示“人物”部分及其内容。但不在工具栏上显示加号。我错过了什么?
用 NavigationView
struct ContentView: View {
var body: some View {
NavigationView{ // Here
Form {
Section(header: Text("People")) {
ForEach(people) { person in
PersonListItem(data: .constant(person))
}
}
}.listStyle(InsetListStyle())
.toolbar {
NavigationLink(destination: NewPerson(personData: .constant(Person.empty))){
Image(systemName: "plus")
}
}.navigationBarTitleDisplayMode(.inline)
}
}
}