美文网首页iOS开发进阶
iOS 10的UICollectionViewDataSourc

iOS 10的UICollectionViewDataSourc

作者: makemake | 来源:发表于2017-10-20 10:42 被阅读25次

    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;
                }
            }
        }
        
    }
    

    相关文章

      网友评论

        本文标题:iOS 10的UICollectionViewDataSourc

        本文链接:https://www.haomeiwen.com/subject/esimuxtx.html