簡體   English   中英

無法使用SDWebImage框架引用圖像

[英]Cant get reference to an image using SDWebImage framework

我有一個表解析XML並獲取URL鏈接加載的圖像的值。 有我的代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


    UILabel *labelText = (UILabel *)[cell viewWithTag:1000];
    labelText.text = [[self.listOfPlaceDetails objectAtIndex:indexPath.row] objectForKey:@"name"];

    if (cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"dashie.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){


    }];

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

return cell;
}

是的,它的工作原理,但現在我需要修改我的UIImage(使用類別,使其大小合適),而我根本無法參考它。 當我試圖在完成塊中修改圖像時,如下所示:

 [cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"dashie.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){

        [image resizedImageWithBounds:CGSizeMake(66, 66)];

    }];

絕對沒有效果,即使我為nil更改圖像,它實際上什么也沒做,所以我的問題是:如何在方法中獲取UIImage的實例變量:

[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"dashie.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){


    }];

並修改它? 或者我怎么能為我之前創建的這個方法傳遞UIImage的實例變量? 這個問題可能聽起來很愚蠢,但我需要建議。

任何幫助將不勝感激,謝謝!

假設沒有錯誤返回到完成塊, [image resizedImageWithBounds:CGSizeMake(66, 66)]; 將為您創建一個新的圖像,但您仍需要使用它做一些事情:

UIImage *resizedImage = [image resizedImageWithBounds:CGSizeMake(66, 66)];
cell.imageView.image = image;

你需要注意,在圖像准備好之前,單元格可能已被重用,因此在塊中使用cell可能是錯誤的。 更好:

UIImage *resizedImage = [image resizedImageWithBounds:CGSizeMake(66, 66)];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = resizedImage;

SDWebImage有圖像下載器,你可以下載圖像,改變你需要的一切並設置為imageView

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM