0

I'm trying to retrieve users profile pictures(File) from Parse onto my PFQueryTableViewController. The code I've written doesn't give me errors but every time I run my app crashes and says "Could not cast value of type UIImageView to PFImageView. I'm new to coding and don't know what that means. Is there something I have to fix in my code? I just want to retrieve the users image to display on my query. Here is my code below for my FeedViewController:

        override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?, object: PFObject!) -> PFTableViewCell? {
       let cell = tableView!.dequeueReusableCellWithIdentifier("BubbleCell", forIndexPath: indexPath!) as! Bubbles


        if let userPost : PFObject = self.posts.objectAtIndex(indexPath!.row) as! PFObject {
/       if let pic = object["photo"] as? PFFile {
            // Make sure your imageView is a PFImageView
            let imageView = cell.userImage as! PFImageView
           // I assume this is the placeholder image while your load your image files from Parse
            imageView.image = UIImage(named: "image.png")
            imageView.file = pic
            // Load the image file however you see fit
           imageView.loadInBackground(nil) 
        }

Here is my code for my PostViewController:

   @IBAction func postPressed(sender: AnyObject) {



        let testObj = PFObject(className: "Test")

        testObj["photo"] = PFUser.currentUser()?.valueForKey("photo") as! PFFile

        testObj.saveInBackgroundWithBlock { (success:Bool, error :NSError?) -> Void in
            if error == nil
            {
                print("***///detail is saved///***")
                self.dismissViewControllerAnimated(true, completion: nil)
            }

    else {
        self.alert()
    }
        }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Bachenenad
  • 65
  • 7
  • 1
    How do you define `userImage` in your `BubbleCell` class? – joern Nov 01 '15 at 19:51
  • I changed it to a PFImageView and now my app crashes with another error saying "terminating with uncaught exception of type NSException" – Bachenenad Nov 01 '15 at 20:02
  • Would you please post the full error message? For example, 2014-10-18 12:07:34.400 soundtest[17081:818922] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key sfdfa.' *** First throw call stack: ( 0 CoreFoundation 0x00000001067813f5 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001082afbb7 objc_exception_throw + 45 2 CoreFoundation – Henry Situ Nov 01 '15 at 23:24
  • where is the code from your PFTableViewCell ? – jjjjjjjj Nov 02 '15 at 00:44

0 Answers0