Lazy loading of image in tableview

前端 未结 5 1853
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 09:57

Im trying to load the image of my uitableviewcells in lazy mode.

I\'m trying to do it in the simplest possible way, I saw a lot of examples but they were going further t

5条回答
  •  时光说笑
    2021-01-25 10:23

    try this one, I'm using always this scheme to load images asynchronously:

    (I haven't found simplest way.)

    - (void)inAnyMethod {
    
        // ...
    
        void (^blockLoadPhoto)() =  ^{
            UIImage *_imageTemporary = [UIImage imageNamed:@"..."];
            if (_imageTemporary) {
                [self performSelectorOnMainThread:@selector(setPhoto:) withObject:_imageTemporary waitUntilDone:true];
            }
        };
    
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), blockLoadPhoto);
    
        // ...
    
    }
    
    - (void)setPhoto:(UIImage *)photo {
        // do something with the loaded image
    }
    

提交回复
热议问题