ばかげた質問かもしれませんが、実際にどうすればいいのかわかりません。
uitableview にアイテムのリストがあります。各セルには uibutton と URL があります。ボタンがタップされると、サーバーからコンテンツのダウンロードを開始します。
これは私が望んでいたようにうまくいきます。今私が知る必要があるのは、viewdidloadが呼び出されたら、各行のダウンロード関数/メソッドを次々と自動的に呼び出す方法です.(ボタンをタップせずに).
行ごとにビデオ、オーディオ、画像ファイルをダウンロードする必要があります。
この関数-(void)downLoad:(id)sender event:(id)event{で、ボタンがタップされたセルを検索/取得できます。したがって、このセルの進行状況を表示できます。しかし、自動的にダウンロードするときにこれらのことを進める方法がわかりません
スレッドの概念を使用する必要があることは理解していますが、その方法がわかりません。
参照/URL/コードを提案してください
以下は私の現在のコードです
-(void)downLoad:(id)sender event:(id)event{
self.tblViewDownload.userInteractionEnabled = NO;
IsRequestCompleted = NO;
CGPoint touchPosition = [[[event allTouches] anyObject] locationInView:self.tblViewDownload];
NSIndexPath *indexPath = [self.tblViewDownload indexPathForRowAtPoint:touchPosition];
UITableViewCell *Cell = [self.tblViewDownload cellForRowAtIndexPath:indexPath];
progress = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
progress.frame = CGRectMake(65, 55, 210, 25);
progress.progress = 0.0;
[Cell.contentView addSubview:progress];
UIButton* button = (UIButton*)sender;
button.hidden=YES;
if(!self.networkQueue)
self.networkQueue = [[[ASINetworkQueue alloc] init] autorelease];
[self.networkQueue cancelAllOperations];
[self.networkQueue setQueueDidFinishSelector:@selector(queueCompleted:)];
[self.networkQueue setShowAccurateProgress:YES];
[self.networkQueue setDownloadProgressDelegate:progress];
[self.networkQueue setDelegate:self];
NSDictionary *aDict =[self.myUrlArray objectAtIndex:[indexPath row]];
NSString *aImgUrl = [aDict objectForKey:@"IMG_URL"];
NSString *aVideoUrl = [aDict objectForKey:@"VIDEO_URL"];
NSString *aAudioUrl = [aDict objectForKey:@"AUDIO_URL"];
NSArray *aPoemArrayUrls = [NSArray arrayWithObjects:aImgUrl,aVideoUrl,aAudioUrl,nil];
for(NSString* urlString in aPoemArrayUrls)
{
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *downloadAFileRequest = [[ASIHTTPRequest requestWithURL:url]retain];
NSString *Filename = [urlString lastPathComponent];
NSLog(@"%@ filename",Filename);
[downloadAFileRequest setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
[downloadAFileRequest setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:Filename]];
[downloadAFileRequest setShouldContinueWhenAppEntersBackground:YES];
[downloadAFileRequest setDelegate:self];
[downloadAFileRequest setDidFinishSelector:@selector(requestDone:)];
[downloadAFileRequest setDidFailSelector:@selector(requestWentWrong:)];
[downloadAFileRequest setShowAccurateProgress:YES];
[self.networkQueue addOperation:downloadAFileRequest];
//----
}
[self.networkQueue go];
}