[英]SDWebImage not displaying download images
我使用SDWebImage
庫從服務器下載遠程圖像。 但是當我在EDGE連接中時,它花費了太多時間,並且在下載NSLog
值后卻顯示了,但是UIButton
下沒有顯示圖像
碼:
int Width = 0;
for (int i = 0; i<[productimg_array count]; i++ ) {
NSLog(@"index %@", productimg_array[i]);
imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 0, 72, 72)];
Width = Width + 20+(i*74);
[imgView1 setTag:i+1];
[imgView1 addTarget:self action:@selector(dbClicked:) forControlEvents:UIControlEventTouchUpInside];
// [imgView1 setImageWithURL:[NSURL URLWithString:[productimg_array objectAtIndex:i]]
// forState:UIControlStateNormal];
[imgView1 setImageWithURL:[NSURL URLWithString:[productimg_array objectAtIndex:i]] forState:UIControlStateNormal completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
NSLog(@"download images 1");
}];
[scrollview addSubview:imgView1];
}
[scrollview setContentSize:CGSizeMake(Width,imgView1.frame.size.height+20)];
可能有錯誤或超時。 嘗試此更改,也許我們可以找到更多:
[imgView1 setImageWithURL:[NSURL URLWithString:[productimg_array objectAtIndex:i]] forState:UIControlStateNormal completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if(error){
NSLog(@"Callback Error:%@",error);
}
if(image){
NSLog(@"Callback Image:%@",image);
}
}];
這是對我有用的東西,我保留了循環,但我不使用它,因此它與您的代碼匹配。 我宣布imgView1為UIButton,並將URL硬編碼為stackoverflow圖像。 我建議您檢查imgView1的類型和productimg_array的內容
int Width = 0;
UIButton *imgView1;
for (int i = 0; i<1; i++ ) {
imgView1=[[UIButton alloc]initWithFrame:CGRectMake(20+(i*74), 0, 72, 72)];
Width = Width + 20+(i*74);
[imgView1 setTag:i+1];
[imgView1 addTarget:self action:@selector(cancelPressed:) forControlEvents:UIControlEventTouchUpInside];
[imgView1 setImageWithURL:[NSURL URLWithString:@"http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=6"] forState:UIControlStateNormal completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
NSLog(@"download images 1");
}];
[self.view addSubview:imgView1];
}
您可以從UIButton+WebCache.h
使用此方法
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state;
稱呼類似
[imgView1 setImageWithURL:[NSURL URLWithString:[productimg_array objectAtIndex:i]] forState:UIControlStateNormal];
此方法將下載圖像並將其直接設置為按鈕。
希望有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.