在SwiftUI中,控制事件在哪里,即scrollViewDidScroll检测列表数据的底部 [英] In SwiftUI, where are the control events, i.e. scrollViewDidScroll to detect the bottom of list data

查看:17
本文介绍了在SwiftUI中,控制事件在哪里,即scrollViewDidScroll检测列表数据的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SwiftUI 中,有谁知道控制事件(例如 scrollViewDidScroll)在哪里检测用户何时到达列表底部导致事件检索额外的数据块?或者有没有新的方法来做到这一点?

In SwiftUI, does anyone know where are the control events such as scrollViewDidScroll to detect when a user reaches the bottom of a list causing an event to retrieve additional chunks of data? Or is there a new way to do this?

好像 UIRefreshControl() 也不存在...

Seems like UIRefreshControl() is not there either...

推荐答案

可以检查最新的元素是否出现在 onAppear 里面.

You can to check that the latest element is appeared inside onAppear.

struct ContentView: View {
    @State var items = Array(1...30)

    var body: some View {
        List {
            ForEach(items, id: \.self) { item in
                Text("\(item)")
                .onAppear {
                    if let last == self.items.last {
                        print("last item")
                        self.items += last+1...last+30
                    }
                }
            }
        }
    }
}

这篇关于在SwiftUI中,控制事件在哪里,即scrollViewDidScroll检测列表数据的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆