在我的代码中的某个地方,我有一个非常标准的列表,其中包含以下部分:
var body: some View {
List {
ForEach(userData.groupedBookings) { group in
Section(header: Text(group.key)) {
ForEach(group.items) { booking in
LessonRow(booking: booking)
}
}
}
}
}
不知何故,使用这段代码,这些部分是可扩展/可折叠的,这让我很高兴,但我不知道为什么。
我特别沮丧,因为我想用类似的代码在其他地方重现这种行为,但没有展开/折叠。
自动获取这个的要求是什么?
它通过侧边栏列表样式激活(在某些情况下被视为默认),您可以显式使用它
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 https://stackoverflow.com/a/63228810/12299030
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)