iOS 10的Tableview 和 CollectionView 出了一個新的DataSourcePrefetching代理。用于解決滑動時候的時候,讓頁面滑動的時候更加流暢。
應(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;
}
}
}
}