Loading images in background to optimize the loading in ios

后端 未结 9 1258
星月不相逢
星月不相逢 2021-02-02 03:02

I am trying to optimize the load in my application, in fact, I have a lot of images that loaded in my application, and I spend a lot of time waiting for a view controller to ope

9条回答
  •  执念已碎
    2021-02-02 03:24

    You can try something like this!....

     dispatch_queue_t checkInQueueForPostImage = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    
                            dispatch_async(checkInQueueForPostImage, ^{
                                UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:postAndCheckInDetails.postImageURL]]];
    
                                dispatch_sync(dispatch_get_main_queue(), ^{
                                    if (image!=nil) {
                                        [uploadImage setImage:image];
                                    }
    
                                    [cell setNeedsLayout];
                                });
                            });
    

提交回复
热议问题