ここのコードhttps://stackoverflow.com/a/7212943/711837に従って、アプリが特定の Web サイトから画像をダウンロードしようとしているインジケーターを表示し始めました。シナリオは次のとおりです。
多くのカスタム セルを含むテーブルビューがあり、カスタム セルには 2 つのラベルとイメージビューがあります。ラベルNSURL
を埋めるコンテンツをダウンロードしてから、画像をダウンロードしてUIImageView
. スピナーと画像のダウンロードのコードは次のとおりです。
resultArray = [[NSArray alloc] initWithArray:response];
[self downloadImageFromInternet:@"http://static.colourlovers.com/images/shapes/0/7/7090/50x50.png"];
//spinner for the download
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
custcell.accessoryView = spinner;
[spinner startAnimating];
///[spinner release];
[self.thetableView reloadData];
そして[spinner stopAnimating]
、クラスの最後のダウンロードメソッドを呼び出しますが、どういうわけか、スピナーはアニメーション化されないか、問題として表示されません! 私は何かを逃していますか?または私が参照できる場所はありますか?私の目的は、ロード後にイメージビューが同じ位置を引き継ぎ、これがすべてのセルにUIIndicatorView
ある場所を表示することです。UIImageView
更新されたメソッドが追加されました
-(void) downloadImageFromInternet:(NSString*)urlToImage{
// Create a instance of InternetImage
asynchImage = [[DownloadThumb alloc] initWithUrl:urlToImage];
// Start downloading the image with self as delegate receiver
[asynchImage downloadImage:self];
}
-(void) internetImageReady:(DownloadThumb*)downloadedImage{
// The image has been downloaded. Put the image into the UIImageView
[arrayImg addObject:downloadedImage.Image];
[spinner stopAnimating];
[self.thetableView reloadData];
}
-(void)downloadImage:(id)delegate{
m_Delegate = delegate;
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:ImageUrl]
cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
imageConnection = [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];
if(imageConnection)
{
workInProgress = YES;
m_ImageRequestData = [[NSMutableData data] retain];
}
}