SwiftUI 中免费可扩展列表的要求是什么? [英] What are the requirements for a free expandable List in SwiftUI?
问题描述
在我的代码中的某处,我有一个带有部分的非常标准的列表:
Somewhere in my code I have this pretty standard list with sections:
var body: some View {
List {
ForEach(userData.groupedBookings) { group in
Section(header: Text(group.key)) {
ForEach(group.items) { booking in
LessonRow(booking: booking)
}
}
}
}
}
不知何故,这段代码的部分是可展开/可折叠的,这让我很高兴,但我不知道为什么.我特别沮丧,因为我想用类似的代码在其他地方重现这种行为,而不是展开/折叠.
Somehow with this code the sections are expandable/collapsable, which makes me happy, but I don't know why. I'm especially frustrated because I want to reproduce this behavior elsewhere with similar code and don't get the expand / collapse.
自动获取此内容的要求是什么?
What are the requirement to automatically get this?
推荐答案
侧边栏列表样式激活(在某些情况下被视为默认),您可以明确使用
It is activated by sidebar list style (which in some conditions are considered as default), which you can use explicitly
List {
ForEach(userData.groupedBookings) { group in
Section(header: Text(group.key)) {
ForEach(group.items) { booking in
LessonRow(booking: booking)
}
}
}
}
.listStyle(SidebarListStyle())
作为替代,您可以显式使用 DisclosureGroup
来对部分进行披露行为,例如 https://stackoverflow.com/a/63228810/12299030
as alternate you can use DisclosureGroup
explicitly to have disclosure behavior for sections, like in https://stackoverflow.com/a/63228810/12299030
这篇关于SwiftUI 中免费可扩展列表的要求是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!