Skip to content

Instantly share code, notes, and snippets.

@kean
Last active December 30, 2015 11:11
Show Gist options
  • Save kean/e689de23ea42b942dddb to your computer and use it in GitHub Desktop.
Save kean/e689de23ea42b942dddb to your computer and use it in GitHub Desktop.
@import DFImageManager;
@interface CustomImageLoadingView
- (void)prepareForReuse;
- (void)setImageWithRequest:(nonnull DFImageRequest *)request;
@end
@implementation CustomImageLoadingView {
DFImageTask *_task;
}
- (void)dealloc {
[self cancelFetching];
}
- (void)prepareForReuse {
[self cancelFetching];
self.image = nil;
}
- (void)cancelFetching {
_task.completionHandler = nil; // Make sure that completion handler is not called for obsolete tasks
[_task cancel];
_task = nil;
}
- (void)setImageWithRequest:(DFImageRequest *)request {
[self cancelFetching];
// TODO: Add activity indicator
typeof(self) __weak weakSelf = self;
_task = [DFImageManager imageTaskForRequest:request completion:^(UIImage *__nullable image, NSError *__nullable error, DFImageResponse *__nullable response, DFImageTask *__nonnull imageTask){
// TODO: Remove activity indicator
weakSelf.image = image;
if (!response.isFastResponse) { // Not from cache
// TODO: Add animations if necessary
}
}];
[_task resume];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment