iOS 10的UICollectionViewDataSourc
2017-10-20 本文已影响25人
makemake
iOS 10的Tableview 和 CollectionView 出了一个新的DataSourcePrefetching代理。用于解决滑动时候的时候,让页面滑动的时候更加流畅。
应该是这样用的:
- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths{
for (NSIndexPath *indexPath in indexPaths) {
if (indexPath.section == self.section && indexPath.item<self.deviceDataSource.count) {
WZBLEDataModel *model = self.deviceDataSource[indexPath.item];
WSTHomeDeviceCell *cell = (WSTHomeDeviceCell *)[collectionView cellForItemAtIndexPath:indexPath];
[cell refreshWithModel:model indexPath:indexPath];
}
}
}
- (void)collectionView:(UICollectionView *)collectionView cancelPrefetchingForItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths{
for (NSIndexPath *indexPath in indexPaths) {
if (indexPath.section == self.section && indexPath.item<self.deviceDataSource.count) {
if (self.deviceDataSource[indexPath.item]) {
WZBLEDataModel *model = self.deviceDataSource[indexPath.item];
model = nil;
}
}
}
}