0

I'm using Parse for my app written in Swift. It is a golf app that allows the user to have a profile. The user can edit the profile on an edit profile view controller, save it and then they're taken back to the main profile view controller. The problem I'm having is if the user changes their profile image and saves it, the image isn't updated on the main profile view controller but the rest of the new profile info is. My belief is the timing is off with the Parse query and the image isn't coming back in time. Here is my query for my main profile page. I tried using the "dispatch_async" method but this doesn't seem to be working. Thanks in advance.

    func getProfileFromBackground() {
    profileData.removeAll()
    if let userQuery = PFUser.query() {
        userQuery.whereKey("username", equalTo: (PFUser.currentUser()?.username)!)
        userQuery.findObjectsInBackgroundWithBlock({ (currentUserProfile:[PFObject]?, error: NSError?) -> Void in
            if error == nil {
                for object:PFObject in currentUserProfile! {
                    self.profileData.append(object)
                    for data in self.profileData {
                     dispatch_async(dispatch_get_main_queue()) {
                     self.golferNameLabel.text = data.objectForKey("name") as? String
                     self.usernameLabel.text = "Username: \(data.objectForKey("username")!)" as String
                     self.golferProfileImage.file = data.objectForKey("profileImage") as? PFFile
                     self.golferProfileImage.loadInBackground()
                       }
                    }
                }
            } else {
                print(error)
            }
        })
    }
 }
dcotter
  • 312
  • 6
  • 22
  • In your case i think you should use PFImageView where you could have a placeholder image while the real picture is being loaded. And also i saw that you are saving those data into an array therefore you should download everything together then instead of requesting connection to parse – Lamour Dec 23 '15 at 06:06
  • I am using PFImageView. The problem is when the Parse query comes back it isn't updating the image. – dcotter Dec 23 '15 at 19:20
  • First of all you need to set the PFImageView with a placeholder image, then you check if the data isnt nil then you assigned it to your PFIImageView and load it – Lamour Dec 23 '15 at 19:22
  • The placeholder image was the user's previous profile image. Thanks for your help though. I just ended up getting it to work by subclassing my PFObject in my query. Besides that I didn't mess with the query and now it changes the image once the image comes back from the query. – dcotter Dec 23 '15 at 19:40
  • I mean if you are using the last user image as a placeholder you should download it then assign it, Then finally get the new image and load it – Lamour Dec 23 '15 at 19:42

0 Answers0