首页 > 解决方案 > 为什么部分框架不会调整大小以显示列表内容

问题描述

我有一个运行 ForEach 以返回标头的部分:然后另一个视图返回内容的 fetchRequest。问题是该部分的内容大小只有 fetchRequest 高的 1 行高。如果我应用大小的修饰符.frame(maxHeight: .infinity)不会改变。如果我申请.frame(maxHeight: 200它确实会变大。

为什么 .infinity 不动态增加高度

    List{
           
            ForEach(books, id: \.self) { thisbook in
                Section(header:
                            HStack {
                           Text(thisbook.number ?? "number string error")
                            Text(thisbook.wrappedFirstname)
                            Text(thisbook.lastName ?? "Last Name string error")
                            Text(thisbook.to ?? "To string error")
                            Text(thisbook.from ?? "From string error")
                            })
                {
                    BookList(filterKey: "number", filterValue: thisbook.wrappednumber){(books: Books) in
                    Text("\(books.wrappedBooks)")
                    }.frame(maxHeight: .infinity)
                
                }
                }

标签: swiftuiswiftui-list

解决方案


推荐阅读