使用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)
}
}
什么都不会改变:
List(0...100, id: \.self) { item in Text("hey \(item)") }
替换列表-仍然不会滚动。.frame()
。.frame
.modifier
和.padding
都什么都没完成。这无关紧要(以下主题包含问答的内容,但不是此问题):
我如何找到可能阻止List()滚动的原因?
答案 0 :(得分:0)
事实证明,问题不在于上面所提出的结构中的任何内容;所有这些都与使用该结构的View有关。具体来说,当Color()
-甚至.opacity(0)
-位于ZStack
上方的List()
中时,后者会停止滚动。显示正常,但不会滚动。
This question描述了同一件事,尽管情况有所不同。
我将保留这个问题,因为其他人可能和我在同一个地方,“为什么我的List()没有滚动?”,而不是“为什么我的List()不是在ZStack中?滚动?”希望早于13的Swift版本可以解决此问题!