這可能是個愚蠢的問題,但我不確定如何解決這個問題。如何使用線程自動爲每行調用函數
我有uitableview中的項目列表。 每個單元格都有uibutton和URL。輕按按鈕時,我開始從服務器下載內容。
這工作正常,因爲我想。現在我需要知道的是,一旦調用了viewdidload,我怎麼可以自動調用每一行的下載函數/方法(不需要點擊按鈕)。
我必須爲每一行下載視頻,音頻和圖像文件。
在此函數中- (void)downLoad:(id)發件人事件:(id)事件{我能夠找到/獲取單元從中輕按按鈕。所以我可以展示這個細胞的進展。但我不知道如何自動下載時如何處理這些事情
我明白我必須使用線程的概念,但我不知道如何去做。
請給我建議任何引用/ 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];
}
請有人幫忙 – user198725878 2012-08-08 13:17:33