2

画像を非同期でダウンロードし、UITableViewに表示しています。画像のダウンロード中は、対応するテーブル行にUIProgressViewが表示されます。ダウンロードが完了したら、進行状況ビューを実際の画像に置き換える必要があります。

ストーリーボードを使用していて、UITableViewCellを、UIImageView responseViewのIBOutletsを持つResponseTableViewCellというクラスとUIProgressView(progressView)にサブクラス化しました。何らかの理由で、ダウンロードが完了した後、進行状況ビューを非表示にすることができません。非表示にしないと、ダウンロードした画像の上に表示されます。非表示にしようとすると、すべての行で非表示になります。これは細胞の再利用に関係していると思います。

また、2つのカスタムセルを作成してみました。1つはUIImageViewを使用し、もう1つはUIProgressViewを使用します。しかし、ストーリーボードでUITableViewCellを追加できる唯一の方法は、UITableViewにドラッグすることです。つまり、2つのUITableViewCellが重なり合っています。

動作するように見える唯一の方法は、UITableViewCellをサブクラス化するのではなく、プログラムで画像ビューと進行状況ビューを作成することですが、私はこの方法でそれを行いたくありません。これが私のコードです:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ResponseTableViewCell *cell = (ResponseTableViewCell*)
    [tableView dequeueReusableCellWithIdentifier:@"ResponseCell"];

    if(indexPath.row == 0) {//display the main image

        cell.responseView.image = _image;
        [cell.progressView setHidden:YES];
        return cell;
    }
      //display responses to the image
      indexPath = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:indexPath.section];
       Photo *response = [ self getResponseAtIndex:indexPath.row];
       NSMutableDictionary* downloadInfo = [self getConnectionInfoForId:[response photoId]];
       if([response fullImage] == nil) {
           float received = [[downloadInfo objectForKey:@"receivedBytes"] floatValue];
           float total = [[downloadInfo objectForKey:@"totalFileSize"] floatValue];

           NSNumber* percentage= [NSNumber numberWithFloat:received/total];
           NSMutableDictionary* userInfo = [[NSMutableDictionary alloc] init];
           [userInfo setObject:cell.progressView forKey:@"cell"];  
           [userInfo setObject:percentage forKey:@"percentage"];  /

           [self performSelectorOnMainThread:@selector(updateProgressView:) withObject:userInfo waitUntilDone:NO
];
           return cell;
        }
        else {
           cell.responseView.image = response.fullImage;
            return cell;
        }
}
4

1 に答える 1

0

これは、投稿したコード以外の何かと関係があるのではないかと思います。しかし、もう一つの問題は

        [cell.progressView setHidden:YES];

後でメインスレッドでprogressvViewを注意深く更新したことがわかりましたが、メインスレッドで実行していませんsetHidden。これは UIProgressView であり、UI コードはメイン スレッド上にあると想定されていsetHiddenます。

于 2012-11-28T22:55:55.107 に答える