2012-03-06 19 views
0

我跟着這裏的代碼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]; 
} 

}

+0

顯示您downloadImageFromInternet方法......很可能你調用它主要thread..which阻止你的UI更新 – Shubhank 2012-03-06 08:03:02

+0

' - (空)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

+0

我如何格式化這些行! :S – eddy 2012-03-06 08:18:29

回答

0

當您創建單元格你真的應該開始微調。
然後,您應該檢查cellForRowAtIndexPath是否應該可見。
最後,當您需要顯示它時,可以使用[tableView reloadData]來顯示或刪除它。

+0

我在CustomCell發起了微調,現在微調旋轉了,然後在'cellForRowAtIndexPath'中,我將圖像設置爲單元格中的圖像視圖,並將imageview的alpha值更改爲1.0(初始值爲0.0)併爲spinner停止動畫,但它不會阻止它...我錯過了什麼?我希望你明白我想說的 – eddy 2012-03-06 15:18:51