SwiftUIの無料の拡張可能なリストの要件は何ですか?
Dec 02 2020
私のコードのどこかに、セクションを含むこのかなり標準的なリストがあります。
var body: some View {
List {
ForEach(userData.groupedBookings) { group in
Section(header: Text(group.key)) {
ForEach(group.items) { booking in
LessonRow(booking: booking)
}
}
}
}
}
どういうわけか、このコードではセクションが展開可能/折りたたみ可能であり、私は幸せですが、理由はわかりません。この動作を同様のコードで他の場所で再現し、展開/折りたたみを取得したくないので、特にイライラします。
これを自動的に取得するための要件は何ですか?
回答
2 Asperi Dec 02 2020 at 15:43
サイドバーリストスタイル(一部の条件ではデフォルトと見なされます)によってアクティブ化され、明示的に使用できます
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