[英]showing progress on imageview on customcell on uitableview
我按照這里的代碼https://stackoverflow.com/a/7212943/711837進行操作,以使我開始展示我的應用程序試圖從特定網站下載圖像的指示器。 該方案是:
我有很多自定義單元格的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占據相同的位置,並且在每個單元格上。
UPDATED添加了方法
-(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];
}
}
創建單元時,您應該真正啟動微調器。
然后,您應該在cellForRowAtIndexPath
檢查它是否可見。
最后,當需要顯示它時,可以使用[tableView reloadData]
顯示或刪除它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.