Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Blocks are made just to makes these things easyer ;-) </p> <p><a href="https://github.com/lombax85/DownloadIOS6" rel="nofollow">HERE</a> you can find an example project. Simply push the + button and insert the direct URL for a file to download. There is no error checking and no URL redirection so insert only direct URLs.<br> For the relevant part look in these methods of the <code>DownloadViewController</code>:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex </code></pre> <p>Here the explanation:</p> <p>When you pass a variable to a block, the block makes a copy of the variables passed from outside. Because our variable is simply an object pointers (a memory address), the pointer is copied inside the block, and since the default storage is __strong the reference is maintained until the block is destroyed.</p> <p>It means that you can pass to the block a direct reference to your progress view (I use an UIProgressView since I've never used MBProgressHUD):</p> <pre><code>UIProgressView *progressView = // create a reference to the view for this specific operation [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) { progressView.progress = // do calculation to update the view. If the callback is on a background thread, remember to add a dispatch on the main queue }]; </code></pre> <p>Doing this, every operation will have a reference to its own progressView. The reference is conserved and the progress view updated until the progress block exists.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload