views:

57

answers:

2

Hello,

I'm trying to build a small app which allows downloading of multiple files at the same time while displaying them in a custom NSTableView. This works, i've done this by using an NSEnumerator, but I struggle at getting the progress right. It's calculated correctly, but it's not done individually for every download, instead they're added up.

The way I've tried to set the subtitles containing the progress is by loading them into a separate array and then inserting/replacing objects containing the progress, but here I run into another problem - I don't know how to get the index of the object that's being downloaded, so I can't differentiate between the progresses.

I hope you understand what I mean :P

I've uploaded the source code to my server, I'd be really grateful if someone could have a look and help me out: http://web.me.com/david.schiefer/MyController.m

Here's a screenshot to visualize what I want to do: http://web.me.com/david.schiefer/progress.tiff

As you can see, the 2nd item is downloading but no progress is displayed, instead the percentage value will go to 300 ish :/

A: 

This might not be relevant to what you are doing, but I've found this approach to be very useful for developing applications and works nicely.

http://iphonedevelopment.blogspot.com/2010/05/downloading-images-for-table-without.html

(You can easily adapt this for doing MacOSX development)

Essentially what you could do is implement a series of 'Downloader' objects that have a delegate to report back to your table, that way you can implement a method that reports the progress % back using a delegate that gets updated as each cell in the table gets drawn.

djhworld
+1  A: 

The delegate methods always include the NSURLDownLoad in question as their first parameter, which you can use with NSArrays -indexOfObject:, e.g.:

- (void)download:(NSURLDownload *)dl didReceiveDataOfLength:(NSUInteger)len {
    NSUInteger index = [myArray indexOfObject:dl];
    // ...
}

Instead of -indexOfObject: you could also:

  • use a wrapper for NSURLDownload and give them additional properties like an index
  • use a dictionary to map NSURLDownloads to rows/cells/...
  • ...
Georg Fritzsche