2

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!

adriennemhenry
  • 133
  • 1
  • 3
  • 17

2 Answers2

5

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 !

Michaël Azevedo
  • 3,874
  • 7
  • 31
  • 45
  • You’re welcome ! It took me a little time to get used to the Parse iOS SDK, now i try to help people here whenever I can. – Michaël Azevedo Mar 11 '14 at 14:20
  • As of ParseUI v 1.1.1 PFImageView has a [loadInBackground:progressBlock:](https://parse.com/docs/ios/api/Classes/PFImageView.html#//api/name/loadInBackground:progressBlock:) – dandan Jul 31 '15 at 18:52
0

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
              }
            }
lguerra10
  • 249
  • 3
  • 5