NSInvalidArgumentException',原因:'不能在PFObject上使用nil作为键或值。使用NSNull表示值。

时间:2014-12-08 04:10:13

标签: ios parse-platform pfobject

尝试创建一个Parse基础iOS应用程序,使用“共享按钮”和以下代码在后台保存对象:

- (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作为值。'“错误。

请帮助......

1 个答案:

答案 0 :(得分:2)

这是Key-Value Coding的一个非常基本的部分(无论你是否使用Parse)。请在KVCNSDictionaryNSArray上查看Apple的文档。

在这种特殊情况下,其中一个值为:photoFile[PFUser currentUser]self.titleTextField.textnil

您应检查输入的有效性,如下所示:

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