2013-05-14 3 views
2

나는 SDWebImage 새 버전을 사용하고 전화 :sdwebImage setImageWithURL : placeholderImage : 완료 :

self.imgIndicatorView.center=self.img.center; 
    self.imgIndicatorView.hidden=NO; 
    [ self.imgIndicatorView startAnimating]; 
    __block UIActivityIndicatorView *indicatorView= self.imgIndicatorView; 

    NSLog(@"myTopics.img.small=%@",myTopics.img.small); 
    [self.img setImageWithURL:[NSURL URLWithString:@"http://ww1.sinaimg.cn/thumbnail/acc940bdj.jpg"] 
          placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){ 

           NSLog(@"newImageNotCached:break.png myTopics.img.small"); 
           if(!error){ 

            CGRect sFrame=self.img.frame; 

            CGSize newSize=image.size; 

            if (newSize.height>80) { 

             if (newSize.width>newSize.height) { 
              newSize.height=newSize.height *80.0/image.size.width; 
              newSize.width=80; 
             }else{ 
              newSize.height=80; 
              newSize.width=newSize.width*80.0/image.size.height; 

             } 


            }else{ 
             if (newSize.width>80) { 
              newSize.height=newSize.height *80.0/image.size.width; 
              newSize.width=80; 
             }else{ 

             } 

            } 
            sFrame.size=newSize; 
            self.img.frame=sFrame; 

            indicatorView.hidden=YES; 
            [indicatorView stopAnimating]; 
            [indicatorView removeFromSuperview]; 
           }else{ 

            self.img.image=[UIImage newImageNotCached:@"break.png"]; 

            indicatorView.hidden=YES; 
            [indicatorView stopAnimating]; 
            [indicatorView removeFromSuperview]; 
           } 


          }]; 

을하지만, 때로는 NSLog 로그 (@ "newImageNotCached : break.png myTopics.img.small"), 경우에 표시되지 URL (@ "http://ww1.sinaimg.cn/thumbnail/acc940bdj.jpg")은 break.so라는 indicatorView가 항상 존재합니다. 왜 메서드가 블록을 호출하지 완료?

답변

1

. 있는 UIImageView + WebCache.m 라인 SdwebImageManager.m 라인에서 55

if (url) 
{ 
    __weak UIImageView *wself = self; 
    id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) 
    { 
     __strong UIImageView *sself = wself; 
     if (!sself) return; 
     if (image) 
     { 
      sself.image = image; 
      [sself setNeedsLayout]; 
     } 
     if (completedBlock && finished) // NOTE: finished == YES, the completedBlock could be called. 

     { 
      completedBlock(image, error, cacheType); 
     } 
    }]; 
    objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 
} 

81

if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && [self.failedURLs containsObject:url])) // NOTE: failedURLs contain the url 
{ 
    // TIPS: ERROR OCCURED, DO NOTHING 
    if (completedBlock) { 
     // NOTE: finished flag was NO. Please set it as YES, And try again. 
     completedBlock(nil, nil, SDImageCacheTypeNone, NO); 
    } 
    return operation; 
} 

그래서 당신이 쓴 completedBlock은 (오류가 발생) 처음에 호출됩니다.

관련 문제