iOS 10中的UICollectionView预取数据源? [英] UICollectionView Prefetch Data Source in iOS 10?

查看:495
本文介绍了iOS 10中的UICollectionView预取数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 10中引入的prefetchDataSources的目的是什么?

What is the purpose of prefetchDataSources introduced in iOS 10?

我刚刚在XCode 8 GM Seed中运行了一个项目,并开始出现错误:

I just ran a project in XCode 8 GM Seed and started getting errors:

MessagesExtension[17902:1238603] *** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3599.6/UICollectionView.m:2161

推荐答案

UICollectionView今年获得了一个名为 prefetchDataSource.就像现有的委托和数据源一样 属性,我们可以简单地将其设置为实现新对象的某个对象 UICollectionViewDataSourcePrefetching协议.

UICollectionView gains a new property this year called prefetchDataSource. Just like the existing delegate and dataSource properties, we can simply set it to some object that implements the new UICollectionViewDataSourcePrefetching protocol.

此协议是iOS 10中的全新协议,并且要求我们仅实现一个新功能:

public func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath])

调用此函数时,我们可以检查indexPaths数组 我们被传递来知道哪些单元格即将出现",因此 我们应该开始为哪些单元格加载数据.

When this function is called, we can examine the indexPaths array we're passed in to know which cells are "coming up soon" and thus which cells we should probably begin loading the data for.

有关示例的详细信息,请参见链接 UICollectionViewDataSourcePrefetching

For detail understanding with example refer link UICollectionViewDataSourcePrefetching

这篇关于iOS 10中的UICollectionView预取数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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