iOS 10的Tableview 和 CollectionView 出了一個(gè)新的DataSourcePrefetching代理。用于解決滑動(dòng)時(shí)候的時(shí)候卡睦,讓頁面滑動(dòng)的時(shí)候更加流暢匣掸。
應(yīng)該是這樣用的:
- (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;
}
}
}
}