1

Question 1 - I am currently writing a program that has a table view that is loaded with data from an on-disk property list. Each of these cells has a name associated with it, and a checkbox. The program's purpose is to have a 'Get' button, and when pressed, will go through the table, checking to see what cells are checked. For each one that is checked, it will grab it's URL (which is just the secondary cell) and download it.

Example

  • x File 1
  • _ File 2
  • x File 3

When pressing 'Get', it will go download the file (Files 1 & 3) from somesite.com/File1.zip, somesite.com/File3.zip.

Currently, what I have written will just download the last file checked.

Question 2 - Once I can figure that out, I would like to know how to download all the files at the same time, rather than in succession, because that's what it looks like my program is doing right now.

Jon Wei
  • 1,481
  • 2
  • 10
  • 18

1 Answers1

0

The class that contains the code invoked by the button should contain:

IBOutlet NSButton *checkbox1;

in the variables area in its header (plus checkbox2 and checkbox3).

This IBOutlet should be connected to the checkbox in the interface layout. Read about IBOutlets in the Cocoa Fundamentals Guide.

As for downloading multiple files simultaneously… you should be using multiple NSURLConnections asynchronously. This can be a little tricky. Have a look at the NSURLConnection documentation. Then also look at this question here for managing multiple connections at once:

Managing multiple asynchronous NSURLConnection connections

Community
  • 1
  • 1
Matt Gallagher
  • 14,858
  • 2
  • 41
  • 43
  • It won't have only 3 checkboxes though. It will have ~300. But doing this outlet method, will each new dynamically created cell/row be able to have its value retrieved through another method? – Jon Wei Jul 11 '12 at 02:37
  • Edit: I also use NSURLDownload for getting the files, not NSURLConnection. Unless it is the same thing. – Jon Wei Jul 11 '12 at 02:50
  • NSURLDownload is always asynchronous. You can download as many as you want. – Matt Gallagher Jul 11 '12 at 03:53
  • 1
    If you're going to have hundreds of checkboxes then you could put them all in a parent view (which you can access through an IBOutlet) and then iterate over all the checkboxes in the parent's subviews. Ultimately though, you should look at MVC – separating your application state into separate classes and having the checkboxes simply reflect that state. It's way to big a topic to discuss in a comment. – Matt Gallagher Jul 11 '12 at 03:56
  • I sort of figured it out with creating a separate class for each object and adding them into an array. It's working as of now. As for NSURLDownload, you said it's always asynchronous? So if I create multiple NSURLRequest w/ NSURLDownloads, they all download at the same time? On my end, it looks like they are all downloaded at separate times. Unless I'm missing something... – Jon Wei Jul 11 '12 at 04:42