0

I have a class which handled the downloads and provides progress information.

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [recievedData appendData:data];
    self.recievedlength = self.recievedlength + [data length];

    // Calculating progress
    self.progress = 0;
    self.progress = ((float)recievedlength / [filesize floatValue]);
    // NSLog(@"%f",self.progress);

    [self performSelectorOnMainThread:@selector(passProgress) withObject:nil waitUntilDone:NO];

I have the following selector which returns the progress information int form of float, in the same class :

  • (float) passProgress {
    //NSLog(@"%f",self.progress); return self.progress; }

My Question is, how do I update the UIProgressView (progress bar) in the MainViewController. The following does not work.

NSLog(@"Progress %f",[classInstance passProgress]);

Any ideas thanks. I do not want to write the download code in the MainViewController.

Kunal Deo
  • 2,248
  • 2
  • 18
  • 27
  • Maybe I'm forgetting something here, but why not just call the method on the UIProgressView to update the value directly from `connection:didReceiveData:`? – Gordon Seidoh Worley Mar 27 '11 at 13:13
  • How do I do that. The code for the view is contained in MainViewController.m . How do I connect it in the interface ?? – Kunal Deo Mar 27 '11 at 13:17
  • You just need to create, in your class to handle downloads, a reference to either MainViewController or the UIProgressView and connect it at runtime. For example, maybe when you initialize the download class you pass it a reference to the UIProgressView. – Gordon Seidoh Worley Mar 27 '11 at 17:03

1 Answers1

0

Write a protocol in your download manager. Adopt that protocol in your main view controller.

YPK
  • 1,851
  • 18
  • 18