Slide Caton problem after loading the data ios UICollectionView

Recent project resource image becomes large, sliding always Caton, where NSOperationQueue solved with a bit

.h 文件
@interface CollectionViewCell : UICollectionViewCell
// 赋值
@property (nonatomic, strong) NearRentListModel *listModel;
// 队列
@property (nonatomic, strong) NSOperationQueue *queue;

.m file
// lazy loading 
- (NSOperationQueue * ) Queue {
    
    if (!_queue) {
        _queue = ({
            NSOperationQueue * Q = [[NSOperationQueue the alloc] the init];
             // set the maximum number of parallel operations is 1 is equivalent to a serial queue thread 
            q.maxConcurrentOperationCount = 1 ;
            q;
        });
    }
    return _queue;
}
// call the set method
 - ( void ) setListModel: (NearRentListModel * ) {ListModel
    
    _listModel = ListModel;
    // here to show additional data (based on project needs)
      
// start using, to solve Caton 
IF (self.queue.operationCount> = 2 ) {
         // If self.queue.operations [0] is being implemented, will not be forced to abort 
        [self.queue cancelAllOperations];
    }
    NSInvocationOperation *operation = [[NSInvocationOperation alloc]
                                        initWithTarget:self
                                        selector:@selector(loadImg)
                                        object:nil];
    
    [self.queue addOperation:operation];
    
}

// call the Display Network Graphics 
- ( void ) {loadImg
    dispatch_async(dispatch_get_main_queue(), ^{
         [_headerImg sd_setImageWithURL:[NSURL URLWithString:_listModel.avatar_path] placeholderImage:MoTo_User_headerimage];
        
        [_img sd_setImageWithURL:[NSURL URLWithString:_listModel.cover_photo] placeholderImage:nil];
    });
}

 

Guess you like

Origin www.cnblogs.com/xingsmile/p/11145471.html
Recommended