问题描述:

Try to create a Parse bases iOS application that saves object in background using a "Share Button" and this code:

- (IBAction)share:(id)sender

{

if (self.chosenImageView.image)

{

NSData *imageData = UIImagePNGRepresentation(self.chosenImageView.image);

PFFile *photoFile = [PFFile fileWithData:imageData];

PFObject *photo = [PFObject objectWithClassName:@"Photo"];

photo[@"image"] = photoFile;

photo[@"whoTook"] = [PFUser currentUser];

photo[@"title"] = self.titleTextField.text;

[photo saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)

{

if (!succeeded)

{

[self showError];

}

}];

}

else

{

[self showError];

}

[self clear];

[self.tabBarController setSelectedIndex:0];

}

Getting the "NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'" Error.

Please Help......

网友答案:

This is a pretty fundamental part of Key-Value Coding (regardless of your use of Parse or not). Please review Apple's documentation on KVC, NSDictionary, and NSArray.

In this particular case, one of these values: photoFile, [PFUser currentUser], or self.titleTextField.text is nil.

You should check your input for validity, like so:

if (photoFile != nil) {
    photo[@"image"] = photoFile;
} else {
    // handle the case where 'photoFile' doesn't exist.
}
相关阅读:
Top