0

カスタムを作成し、その他のクラスでtableViewカスタムtableViewクラスを使用してtableView..

サーバーから画像を読み込んで表示していtableViewRowます..それぞれimageが異なります..

画面には10枚の画像のうち7枚しか表示されず、下にスクロールすると最初の3枚の画像がしばらく繰り返され、それらの画像が読み込まれると適切な画像が表示されます..しかし、最初は新しい画像が表示されるまで古い画像が表示されます。古い画像の代わりに画像が読み込まれていることを示すアクティビティ インジケーターを配置したい..

get load..まで、activity Indicatorの代わりに追加したい。imageimage

私のコードは...

self.tableViewX = tableView;
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView1 dequeueReusableCellWithIdentifier:simpleTableIdentifier];
 if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
    {
NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"];
cell.thumbnailImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]]];
 });

いくつかのサンプルコードで私を助けてください..

4

1 に答える 1

4

「AsyncImageView」クラスファイルを使用すると、画像が同期的に読み込まれ、画像の読み込み中にアクティビティインジケーターが表示されます

次のリンクから「AsyncImageView」クラス ファイルをダウンロードできます。- https://www.dropbox.com/s/peazwjvky9fsjd7/Archive.zip

.m ファイルで AsyncImageView クラスをインポート

 #import "AsyncImageView.h" 

indexpathメソッドのテーブルビューセルで

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *simpleTableIdentifier = @"SimpleTableCell";
     SimpleTableCell *cell = (SimpleTableCell *)[tableView1 dequeueReusableCellWithIdentifier:simpleTableIdentifier];
     if (cell == nil)
     {
           NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
      cell = [nib objectAtIndex:0];
     }
     NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"];
     AsyncImageView *async = [[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
     [async loadImageFromURL:[NSURL URLWithString:imageURL]];
     [cell.thumbnailImageView addSubview:async];
}

これを試してみてください。問題は解決します。

于 2013-03-11T04:39:32.657 に答える