iOS 使用SDwebImage缓存图片并在断网时候显示

 [_loadImageView setShowActivityIndicatorView:YES];
    [_loadImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _loadImageView.contentMode = UIViewContentModeScaleAspectFill;
    [_loadImageView sd_setImageWithURL:self.imageUrl placeholderImage:nil];
    // 缓存图片
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    manager.delegate = self;
   
    [manager.imageDownloader downloadImageWithURL:self.imageUrl options:SDWebImageDownloaderContinueInBackground progress:^(NSInteger receivedSize, NSInteger expectedSize) {
       
    } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
        NSLog(@"---save image is %@",image);
        [manager.imageCache storeImage:image forKey:@"one"toDisk:YES];
    }];
 // 从缓存取图片并显示
SDWebImageManager *manager = [[SDWebImageManager alloc] init];
    UIImage *image = [manager.imageCache imageFromMemoryCacheForKey:@"one"];
posted @ 2016-02-17 15:27  jgCho  阅读(2100)  评论(1编辑  收藏  举报