Ios NSInvalidArgumentException';,原因:';Can';不要对PFObject上的键或值使用nil。对值使用NSNull;
尝试创建一个Parse bases iOS应用程序,使用“共享按钮”在后台保存对象,代码如下:Ios NSInvalidArgumentException';,原因:';Can';不要对PFObject上的键或值使用nil。对值使用NSNull;,ios,parse-platform,pfobject,Ios,Parse Platform,Pfobject,尝试创建一个Parse bases iOS应用程序,使用“共享按钮”在后台保存对象,代码如下: - (IBAction)share:(id)sender { if (self.chosenImageView.image) { NSData *imageData = UIImagePNGRepresentation(self.chosenImageView.image); PFFile *photoFile = [PFFile fileWithDat
- (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];
}
获取“NSInvalidArgumentException”,原因:“不能对PFObject上的键或值使用nil。对值使用NSNull。”错误
请帮助……这是的一个非常基本的部分(无论您是否使用Parse)。请查看有关和的苹果文档 在这种特殊情况下,以下值之一:
photoFile
、[PFUser currentUser]
或self.titleTextField.text
为nil
您应该检查输入的有效性,如下所示:
if (photoFile != nil) {
photo[@"image"] = photoFile;
} else {
// handle the case where 'photoFile' doesn't exist.
}
尝试调试或插入常量,并使用断点,在该断点中您得到的键值错误,您插入的对象得到的值为零。我尝试了这些建议…现在似乎我的PFObject类根本没有在Parse中保存或创建。有什么建议吗???不幸的是,我对解析一无所知。我终于得到了它…让我发疯了。。而不是PFFile*photoFile=[PFFile fileWithData:imageData];应该是。。。。。。。。PFFile*photoFile=[PFFile fileWithName:self.titleTextField.text data:imageData];PFObject*photo=[pfobjectobjectwithclassname:@“photo”];pffile需要显式名称和数据源。