3

SDWebImageカスタムでライブラリを使用しようとしていますUITableViewCell。以下は、Web サービスから画像をダウンロードするメソッドです。

- (void) downloadThumbnails:(NSURL *)finalUrl
{
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    [manager downloadWithURL:finalUrl
                     options:0
                    progress:nil
                   completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
     {
         if (image)
         {
             // do something with image
             // THERE I HAVE TO ASSIGN the property "thumbnail" with the "image"
             // So it can be used by the tableview controller class
         }
     }];

}

上記のコードは、RSSItem. 私のUITableViewControllerクラスには次のcellForRowAtIndexPathメソッドがあります:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ItemsCell";

    ItemsViewCell *cell = (ItemsViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    RSSItem *item = [[channel items] objectAtIndex:[indexPath row]];

    cell.titleLabel.text = [item title];
    cell.creatorLabel.text = [item creator];
    cell.pubTimeLabel.text = [item pubTime];
    cell.thumbContainer.image = [item thumbnail];

    return cell;
}

downloadThumbnails メソッド内で if (画像) を構成する方法を誰かが指摘できますか? プロパティ「サムネイル」に「画像」を割り当てる必要があるだけですが、どうすればよいですか?

4

1 に答える 1

4

SDWebImage を使用して画像を非同期にダウンロードするための適切な方法を既に使用しているようです。必要なのは、サムネイル プロパティを「画像」に設定することだけです。これを行う方法は次のとおりです。

- (void) downloadThumbnails:(NSURL *)finalUrl
{
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    [manager downloadWithURL:finalUrl
                     options:0
                    progress:nil
                   completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
     {
         if (image)
         {
             [self setThumbnail:image];
         }
     }];

}
于 2013-06-13T08:25:18.633 に答える