【问题标题】:UICollectionview insertItemsAtIndexPaths stops scrollingUICollectionview insertItemsAtIndexPaths 停止滚动
【发布时间】:2015-10-22 22:40:01
【问题描述】:

我有一个无限加载collectionview - 添加新项目:insertItemsAtIndexPaths

但是每次我打电话给insertItemsAtIndexPaths 时,滚动都会停止 insertItemsAtIndexPaths 必须在主线程上运行

有什么办法可以阻止insertItemsAtIndexPaths 停止滚动? (我的意思是快速滚动)

问候

【问题讨论】:

    标签: ios cocoa-touch uicollectionview


    【解决方案1】:

    感谢您的提问和回答 Helmut,这似乎太晦涩难懂了,以至于我觉得还有另一个问题在起作用。我找不到除此之外的任何帖子,所以我开始思考还有什么影响滚动并发现我会调用

    refreshControl?.endRefreshing()
    

    当我得到我的新数据时,虽然刷新控件当前没有刷新它仍然会中断滚动。 只需将其更改为以下即可解决问题。

    if let refreshing = refreshControl?.isRefreshing, refreshing {
        refreshControl?.endRefreshing()
    }
    

    【讨论】:

    • 这结束了我对滚动性能欠佳背后原因的毫无结果的搜索。由于难以解释的原因,我在每次调用 cellForItemAt() 时都调用 endRefreshing()。更新了较新版本的 Swift (5.1) ` if let refresh = refreshControl?.isRefreshing, refresh { refreshControl?.endRefreshing() } `
    【解决方案2】:

    所以我回答我自己的问题:)

    将触发insertItemsAtIndexPath 的代码从scrollViewDidScroll 移动到scrollViewDidEndDecelerating - 解决了问题:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-12
      相关资源
      最近更新 更多