Question

Does anybody know how to set the Progress View Bar for a PFImageView, that is downloading a PFFile from (Parse.com)? I can't find any tutorials on how to do so. (I don't want to set an activity indicator since I'm loading an image and I want the user to know how long he/she will wait).

Thanks!

Was it helpful?

Solution

PFImageView methods are quite limited, you can just use loadInBackground , with or without a completion block. In none of these methods a progressBlock is available.

A workaround would be not to assign a PFFile to a PFImageView, but instead load it with a method using a progressBlock parameter.

[myImageFile getDataInBackgroundWithBlock:^(NSData * result, NSError *error)
{ 
     if (result != nil && error == nil)
     {
          [myImageView setImage:[UIImage imageWithData:result]];
     }
     else
     {
          // handle the error
     }
 }
 progressBlock:^(int percentDone)
 {
     [progressView setProgress:(float)percentDone/100.0f];
 }];

This is not as simple as [myPFImageView loadInBackground], but I can't see any other way to get a progress indicator. Note that using a PFImageView is no longer necessary in this case, a simple UIImageView will be sufficient. Maybe one day Parse team will add a progressBlock to their PFFile methods !

OTHER TIPS

My solution: Show a loader.
In an extension to PFImageView use the following code to show a loader

let loader = UIActivityIndicatorView(frame: CGRectMake(self.frame.width/2 - 5, self.frame.height/2 - 5, 10, 10))
        loader.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
        loader.startAnimating()
        self.addSubview(loader)
loadInBackground{(image: UIImage?, error: NSError?) -> Void in
              loader.stopAnimating()
              if error == nil {
                self.image = image
              }
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top