Xcode 15 Beta 6中SidebarListStyle不再显示折叠/展开按钮
- 问题明确:iOS 16环境下,嵌套在VStack内的List使用
.listStyle(SidebarListStyle())时,每个Section会自动显示折叠/展开按钮;但升级到Xcode 15 Beta 6(对应iOS 17 Beta 6)后,该按钮消失,尝试其他listStyle选项也无法恢复,且不想自定义Section Header。 - 可能原因:结合iOS & iPadOS 17 Beta 6发布说明的新特性,大概率是苹果对SidebarListStyle的Section交互逻辑做了调整——目前无法确定是Beta版本的潜在Bug,还是官方有意修改的预期行为。
- 无需自定义Header的解决方案:
- 用
DisclosureGroup替代Section原生折叠逻辑,将展开状态绑定到ViewModel的字典属性,既保留折叠功能,又不用修改原有Header样式:// 先在ViewModel中添加存储展开状态的属性(根据log.Id实际类型调整键的类型) @Published var expandedSections: [String: Bool] = [:] // 列表代码修改如下 List { ForEach(searchResults, id: \.Id) { log in let filteredLogs = vm.filterLogs(logs: log.logs!) if log.logs?.count ?? 0 > 0 && filteredLogs.count > 0 { DisclosureGroup(isExpanded: $vm.expandedSections[log.Id, default: true]) { ForEach(filteredLogs, id: \.Id) { record in Button(action: { vm.selectedLog = log vm.selectedRecord = record isShowingDetailSheet.toggle() }, label: { RecordView(record: record) }) } } label: { Text(vm.getSectionText(log: log)) .font(.title3) .fontWeight(.bold) .foregroundColor(.primary) } } } } .listStyle(SidebarListStyle()) - 若暂时不想修改代码,可降级到Xcode 14/iOS 16环境开发,待iOS 17正式版发布后再验证该问题是否存在。
- 用
- 后续建议:关注iOS 17后续Beta版本的发布说明,若官方未将此现象标注为预期变更,可通过Apple开发者反馈平台提交Bug报告。
内容的提问来源于stack exchange,提问作者nwolfe09
相关产品推荐
相关产品推荐

