0

It might be silly question but I am not sure how to go with the issue really.

I have list of items in uitableview. Each cell has uibutton and URL. When a button is tapped, I start downloading content from server.

This works fine as I wanted. Now what I need to know is how can I call downloading function / method for each row one after another automatically once viewdidload is called.(without tapping a button).

I have to download video, audio and image file for every row.

In this function -(void)downLoad:(id)sender event:(id)event{ I am able to find / get cell from which the button is tapped. So I can show progress for this cell. But I don't know how to proceed with these things when downloading automatically

I understand I have to use Threading concept, but I am not sure how to do it.

Please suggest me any reference/url /code to do

Below is my current code

-(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];

}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
user198725878
  • 6,266
  • 18
  • 77
  • 135

1 Answers1

1

You can use EGOImageView and just assign Image Url to it.It will automatically manage all things

Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
  • hi, i want to download video, audio and image file for every row.pls let me know – user198725878 Aug 08 '12 at 12:18
  • then you have to use NSOperationQueue. But I don't think you will display video in your tableCell ? You can create a dataModal containing these 3 URLS then run a for loop create a NSInvocationOperation like this NSInvocationOperation *nextOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(yourFunctionHere:) object:dataModal]; in your function call to web service to get data from those URL's add this task to NSOperationQueue. – Rahul Vyas Aug 08 '12 at 12:23
  • I am not displaying video in the tableviewcell.in the tableview cell i have to show uiprogressview.can you please tell me how to start calling the sme funtion one after another row.do i need to use looping – user198725878 Aug 08 '12 at 12:27
  • I already told you in comment. You need to use Loop Obviously – Rahul Vyas Aug 09 '12 at 10:53
  • Can you please give me an example that how to do please – user198725878 Aug 09 '12 at 10:58
  • i have created a custom class containing 3 urls.then now do i need to run a loop in this custom class?pls let me know – user198725878 Aug 09 '12 at 11:27