Using SwiftUI, I have a List of items retrieved from CoreData. Everything I read makes it look like the list should be something I can scroll normally, but in both the simulator and running on an iPad, the List doesn't scroll.
Clearly there is some piece missing, but I can't seem to find what it is. The list populates correctly, but it simply won't scroll.
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)
}
}
Things that didn't change anything:
- Removing the ZStack { }
- Replacing the List with a simple
List(0...100, id: \.self) { item in Text("hey \(item)") }
-- still won't scroll. - Adding a
.frame()
to the List() itself. - (added) removing the
.frame
.modifier
and.padding
all accomplished nothing.
This is not about (the following topics have Q&A's addressing them, but not this issue):
- programmatic scrolling
- disabling scrolling
- scroll indicators
- ScrollView
- UIKit
How can I track down what might be preventing the List() from scrolling?
RoundedEdge
modifier? Did you try to remove it as well?self
? e.g.List(self.people, id: \.id) { person in
.modifier(RoundedEdge())
, no change. The list populates fine, and when I make the list as simply being numbers 1...100, same behavior, so not thinking it's a matter of the.id
either. Maybe an issue with the View where this struct is showing up...