Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate UIProgressView in UICollectionViewCell for download file
    primarykey
    data
    text
    <p>I'm trying to update the UIProgressView in UICollectionViewCell when I download a file, but sometime the progressView update and sometime doesn't update, and I can't understand why, this is the code to display the UICollectionViewCell:</p> <pre><code>-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"documentCell"; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; NSManagedObject *doc = [self.magDocument objectAtIndex:indexPath.row]; UIButton *btn = (UIButton *)[cell viewWithTag:2003]; [btn addTarget:self action:@selector(addDocument:) forControlEvents:UIControlEventTouchUpInside]; UIProgressView *progressBar = (UIProgressView *)[cell viewWithTag:2005]; return cell; } </code></pre> <p>This is the button to start the download:</p> <pre><code>- (IBAction)addDocument:(id)sender { self.directCellPath = [self.myCollectionView indexPathForCell:(UICollectionViewCell *)[[sender superview] superview]]; NSManagedObject *document = [self.magDocument objectAtIndex:self.directCellPath.row]; [self loadLink:[document valueForKey:@"docUrl"]]; } - (void)loadLink:(NSString *)urlDownload { UICollectionViewCell *cell = (UICollectionViewCell *)[self.myCollectionView cellForItemAtIndexPath:self.directCellPath]; UIProgressView *prg = (UIProgressView *)[cell viewWithTag:2005]; AFDownloadRequestOperation *request = [[AFDownloadRequestOperation alloc] initWithRequest:requestUrl targetPath:zipDownloadPath shouldResume:YES]; [request setProgressiveDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) { NSLog(@"%f",totalBytesReadForFile/(float)totalBytesExpectedToReadForFile); NSArray *progress = [NSArray arrayWithObjects:prg,[NSNumber numberWithFloat:totalBytesReadForFile/(float)totalBytesExpectedToReadForFile], nil]; [self performSelectorOnMainThread:@selector(updateProgressBar:) withObject:progress waitUntilDone:NO]; }]; [self.downloadQueue addOperation:request]; } - (void)updateProgressBar:(NSArray *)progress { UIProgressView *pgr = (UIProgressView *)[progress objectAtIndex:0]; [pgr setProgress:[[progress objectAtIndex:1] floatValue]]; } </code></pre> <p>One time the the progress view works, and other one thousand times doesn't work, I can't understand how update the progress view, any help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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