lor*_*nzo 4 expandable swiftui swiftui-list
在我的代码中的某个地方,我有一个非常标准的列表,其中包含以下部分:
var body: some View {
List {
ForEach(userData.groupedBookings) { group in
Section(header: Text(group.key)) {
ForEach(group.items) { booking in
LessonRow(booking: booking)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
不知何故,使用这段代码,这些部分是可扩展/可折叠的,这让我很高兴,但我不知道为什么。我特别沮丧,因为我想用类似的代码在其他地方重现这种行为,但没有展开/折叠。
自动获取这个的要求是什么?
它通过侧边栏列表样式激活(在某些情况下被视为默认),您可以显式使用它
List {
ForEach(userData.groupedBookings) { group in
Section(header: Text(group.key)) {
ForEach(group.items) { booking in
LessonRow(booking: booking)
}
}
}
}
.listStyle(SidebarListStyle())
Run Code Online (Sandbox Code Playgroud)
作为替代方案,您可以DisclosureGroup显式使用部分的公开行为,例如/sf/answers/4426016731/
| 归档时间: |
|
| 查看次数: |
1188 次 |
| 最近记录: |