1

私はSDWebImageとUITableViewで作業しています

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

    NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier"];
    NSDictionary *info = [tableData objectAtIndex:indexPath.row];

    UITableViewCell *cell = [the_tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease];
        if(!addImage) [addImage release];
        addImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]];
        [addImage setFrame:CGRectMake(7, 10, 50, 50)];
        [cell setIndentationLevel:6];
        [cell.contentView addSubview:addImage];
    }

    if(info !=  NULL) {
        cell.textLabel.text = [info objectForKey:@"title"];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"Version: %@",[info objectForKey:@"version"]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        NSString *imageURL = [NSString stringWithFormat:@"%@",[info objectForKey:@"imageURL"]];
        [addImage setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];         
    }
    return cell;
}

最初の 6 つの結果に最適な機能 (即時ビューに収まる量)

しかし、リストを下にスクロールすると、最初の 6 つのセルの画像を再利用しているように見えます。一部のセルでは、画面上の位置に応じて画像が変化します。

また、 reloadData を呼び出すと、以前の UITableCells の画像が画面に残ります!

ここで何か間違ったことをしていますか?私はgithubのサンプルコードに従いました..

ありがとう!

4

1 に答える 1

0

(質問編集でOPが回答しました。コミュニティwikiの回答としてここに移動しました。回答がない質問を参照してください。ただし、コメントで問題が解決されました(またはチャットで拡張されました)

OP は次のように書いています。

OK、問題が見つかりました。

同じ問題を抱えている他の人にとって、これはあなたが間違っているところです!

セルの作成中にサブビューに画像を追加する方法に注意してください。

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease];
addImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]];
[addImage setFrame:CGRectMake(7, 10, 50, 50)];
[cell.contentView addSubview:addImage];

さて、SDWebImageやろうとしていたのは、そのaddImage変数を常に更新することでした。これは、私のセル クラスのプロパティではありませんでした。

したがって、この問題を解決するために私が行ったことは、独自のUITableViewCellサブクラスを作成することです。その init には a がImageViewあり、そのプロパティに到達SDWebImagesetImageます!

これが誰かに役立つことを願っています!

于 2015-01-27T09:42:35.203 に答える