【发布时间】:2020-03-22 05:05:32
【问题描述】:
这是一个无限滚动的简单示例。如何为向上滚动添加无穷大
并在开头插入行:
rows.insert(contentsOf: Array(repeating: "Item 0", count: 20), at: 0)
像苹果一样在日历中做这个技巧。
struct Screen: View {
@State var rows: [String] = Array(repeating: "Item", count: 20)
private func getNextPageIfNecessary(encounteredIndex: Int) {
guard encounteredIndex == rows.count - 1 else { return }
rows.append(contentsOf: Array(repeating: "Item", count: 20))
}
var body: some View {
...
List(0..<rows.count, id: \.self) { index in
Text(verbatim: self.rows[index])
.onAppear {
self.getNextPageIfNecessary(encounteredIndex: index)
}
}
【问题讨论】:
-
您可以在末尾添加一个空的“清除”行,然后在该“onAppear”中添加更多行......
-
是的。我知道。怎么在上面!还没结束!