列表不滚动(在SwiftUI中--用于消除其他问题的歧义)

列表不滚动(在SwiftUI中--用于消除其他问题的歧义),swiftui,swiftui-list,Swiftui,Swiftui List,使用SwiftUI,我有一个从CoreData检索的项目列表。我读的每一篇文章都让我觉得列表应该是我可以正常滚动的,但是在模拟器和iPad上运行时,列表都不会滚动 struct PeopleList : View { @Environment(\.managedObjectContext) var managedObjectContext @FetchRequest( entity: Person.entity(), sor

使用SwiftUI,我有一个从CoreData检索的项目列表。我读的每一篇文章都让我觉得列表应该是我可以正常滚动的,但是在模拟器和iPad上运行时,列表都不会滚动

struct PeopleList : View {    
    @Environment(\.managedObjectContext) var managedObjectContext
     
     @FetchRequest(
        entity: Person.entity(),
         sortDescriptors: [
            NSSortDescriptor(keyPath: \Person.lastName, ascending: true),           
            NSSortDescriptor(keyPath: \Person.firstName, ascending: true)
         ]
     ) var people: FetchedResults<Person>
    
    var body: some View {
        ZStack(alignment: .topLeading) {
            List(self.people, id: \.self) { person in
                Text(person.descriptionForList())                                             
             }                          
        }
        .frame(width: 400, height: 200)
        .modifier(RoundedEdge(width: 4, color: Color(red: 0.6, green: 0.6, blue: 0.6), cornerRadius: 10))
        .padding(10)
    }
}
很明显,有一块丢失了,但我似乎找不到它是什么。列表会正确填充,但不会滚动

struct PeopleList : View {    
    @Environment(\.managedObjectContext) var managedObjectContext
     
     @FetchRequest(
        entity: Person.entity(),
         sortDescriptors: [
            NSSortDescriptor(keyPath: \Person.lastName, ascending: true),           
            NSSortDescriptor(keyPath: \Person.firstName, ascending: true)
         ]
     ) var people: FetchedResults<Person>
    
    var body: some View {
        ZStack(alignment: .topLeading) {
            List(self.people, id: \.self) { person in
                Text(person.descriptionForList())                                             
             }                          
        }
        .frame(width: 400, height: 200)
        .modifier(RoundedEdge(width: 4, color: Color(red: 0.6, green: 0.6, blue: 0.6), cornerRadius: 10))
        .padding(10)
    }
}
struct PeopleList:View{
@环境(\.managedObjectContext)变量managedObjectContext
@获取请求(
实体:Person.entity(),
sortDescriptors:[
NSSortDescriptor(键路径:\Person.lastName,升序:true),
NSSortDescriptor(键路径:\Person.firstName,升序:true)
]
)var人员:获取结果
var body:一些观点{
ZStack(对齐:。顶部引导){
列表(self.people,id:\.self){person in
文本(person.descriptionForList())
}                          
}
.框架(宽:400,高:200)
.修改器(圆角边缘(宽度:4,颜色:颜色(红色:0.6,绿色:0.6,蓝色:0.6),拐角半径:10))
.填充(10)
}
}
没有改变任何事情的事情:

  • 移除ZStack{}
  • 将列表替换为简单的
    列表(0…100,id:\.self){item in Text(“hey\(item)”)}
    --仍然不会滚动
  • .frame()
    添加到列表()本身
  • 添加了)删除
    .frame
    .modifier
    .padding
    都没有任何效果
这不是关于(以下主题有问答,但不是这个问题):

  • 程序滚动
  • 禁用滚动
  • 滚动指示器
  • 滚动视图
  • UIKit

我如何追踪可能阻止列表()滚动的原因?

事实证明,问题不在于上面提出的结构中的任何内容;这一切都与使用该结构的视图有关。具体地说,当
Color()
--即使是
.opacity(0)
--位于
列表()上方的
ZStack
中时,后者停止滚动。显示良好,但不会滚动

struct PeopleList : View {    
    @Environment(\.managedObjectContext) var managedObjectContext
     
     @FetchRequest(
        entity: Person.entity(),
         sortDescriptors: [
            NSSortDescriptor(keyPath: \Person.lastName, ascending: true),           
            NSSortDescriptor(keyPath: \Person.firstName, ascending: true)
         ]
     ) var people: FetchedResults<Person>
    
    var body: some View {
        ZStack(alignment: .topLeading) {
            List(self.people, id: \.self) { person in
                Text(person.descriptionForList())                                             
             }                          
        }
        .frame(width: 400, height: 200)
        .modifier(RoundedEdge(width: 4, color: Color(red: 0.6, green: 0.6, blue: 0.6), cornerRadius: 10))
        .padding(10)
    }
}
描述同样的事情发生,尽管情况有所不同


我将保留这个问题,因为其他人可能与我在同一个位置,“为什么我的列表()不滚动?”,而不是“为什么我的列表()不在ZStack滚动?”希望13之后的Swift版本能够修复此行为

什么是
roundedge
修饰符?您是否也尝试将其删除?不使用Roundedge和滚动重新创建是否适用于meDoes Person?是否包含唯一字段,例如id?您是否尝试使用唯一标识符而不是
self
?e、 g.
List(self.people,id:\.id){person in
注释掉了
.modifier(roundedge())
,无更改。列表填充很好,当我将列表设置为数字1…100时,同样的行为,所以也不认为这是
.id
的问题。可能是显示此结构的视图有问题。。。