我跟着這裏的代碼https://stackoverflow.com/a/7212943/711837讓我開始顯示一個指示器,我的應用程序試圖從特定網站下載圖像。場景是:在uitableview上的customcell上顯示imageview的進度
我有一個tableview與許多自定義單元格,自定義單元格有2個標籤和imageview。 我有一個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]
在類的下載完畢的方法,但不知何故,紡紗只是不動畫,或出現的事!我錯過了什麼?還是有我可以參考的地方?我的目標是在UIImageView
處顯示UIIndicatorView
,然後加載後,imageview佔據相同的位置,並且這在每個單元格上。
已更新添加的方法
-(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];
}
}
顯示您downloadImageFromInternet方法......很可能你調用它主要thread..which阻止你的UI更新 – Shubhank 2012-03-06 08:03:02
' - (空)downloadImageFromInternet:(的NSString *)urlToImage { \t //創建一個實例InternetImage \t asynchImage = [[DownloadThumb alloc] initWithUrl:urlToImage]; \t \t //開始下載與自己的圖像作爲代表接收器 \t [asynchImage downloadImage:self]; } - (空)internetImageReady:(DownloadThumb *)downloadedImage {\t \t //圖像已被下載。將圖像放入UIImageView \t [arrayImg addObject:downloadedImage.Image]; \t [spinner stopAnimating]; \t [self.thetableView reloadData]; }' 後者用於下載數據時 – eddy 2012-03-06 08:18:01
我如何格式化這些行! :S – eddy 2012-03-06 08:18:29