0

So, I created a singleton class for my ASIHTTPRequest and a network queue. It downloads the file in the background with no problem. However, because I'm initiating the download from one view, and then the user has the option to change tabs to view a download queue. WHen I switch to the tab the progress bar is not updating. I'm not sure how to get a progress bar in another view controller to update.

if (!self.queue) {
    appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    self.queue = [[[ASINetworkQueue alloc] init] autorelease];
    [self.queue setMaxConcurrentOperationCount:1];
    [self.queue setDownloadProgressDelegate:self];
}

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

[request setDownloadDestinationPath:desPath];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[self.queue addOperation:request]; //queue is an NSOperationQueue
[self.queue go];

So the question is: Since the above code runs in the background, how can I set the setDownloadProgressDelegate to update a progressView in another view controller? I already have a tableview with the files it's going to download, and have a view just above the tableview that should show the progress of the file being downloaded. Adding to the queue and downloading isn't the problem. It's just getting the progress bar to update.

user580340
  • 141
  • 1
  • 5

1 Answers1

0

Try setting the DownloadProgressDelegate to another class, like your AppDelegate, and use that to decide which view to update the progress bar in.

AW101
  • 1,620
  • 14
  • 15
  • I tried instantiating the download view in the Appdelegate, and accessing that view controller. This way I could access the same instance of the download view controller. I was able to access it using [self.queue setDownloadProgressDelegate:appDelegate.dlView]; However, if I try to use [self.queue setDownloadProgressDelegate:appDelegate.dlView.downloadBar] it doesn't even touch the progress view and compiles without warnings. When I run the app in the simulator and switch back to the downloads tab, progress doesn't update with the exception of the UILabels that show what is being downloaded. – user580340 Jul 22 '12 at 19:23
  • I would set it to the app delegate itelf, as in: [self.queue setDownloadProgressDelegate:appDelegate]; and implement -(void)setProgress: in your app delegate that keeps track of the progress (or updates the view accordingly. Also, try setting showAccurateProgress:YES on the request. – AW101 Jul 22 '12 at 20:06
  • Nope, the ASIHTTPRequest calls the -(void)setProgress however it only calls it once. I tried setting up an NSTimer but that didn't work. I'ave also implemented ASIHTTPRequestDelegate & ASIProgressDelegate. If I put setProgress in the AppDelegate, the progress view isn't updated, if I put it in my download view, same thing. Tried writing the float to userdefaults in an NSTimer, but still stays at 0.00. – user580340 Jul 22 '12 at 20:57