gpt4 book ai didi

iphone - sdwebImage setImageWithURL : placeholderImage: completed:

转载 作者:行者123 更新时间:2023-12-03 21:15:30 27 4
gpt4 key购买 nike

我使用SDWebImage新版本并调用:

    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 ") 是否中断。因此指标 View 始终存在。为什么该方法不调用已完成的 block ?

最佳答案

在。 UIImageView + WebCache.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);
}

在 SdwebImageManager.m 第 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只会在第一次(发生错误时)被调用。

关于iphone - sdwebImage setImageWithURL : placeholderImage: completed:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16538850/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com