在视图控制器中,用户可以从照片库中选择图像,添加文本,然后在按下按钮后,应用程序应该创建一个PFObject并将其保存在后台。这是我的按钮操作代码方法:
-(IBAction)sendPressed:(id)sender
{
NSLog(@"boton subir cadena pulsado");
//Upload a new picture
NSData *pictureData = UIImagePNGRepresentation(self.imageView.image);
PFFile *file = [PFFile fileWithName:@"img" data:pictureData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded){
NSLog(@"IMAGEN CARGADA");
//Add the image to the object, and add the comments
PFObject *imageObject = [PFObject objectWithClassName:@"cadenas"];
[imageObject setObject:file forKey:@"image"];
[imageObject setObject:self.commentTextField.text forKey:@"chain_name"];
[imageObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded){
//Go back to the wall
[self.navigationController popViewControllerAnimated:YES];
}
else{
NSString *errorString = [[error userInfo] objectForKey:@"error"];
[self showErrorView:errorString];
}
}];
}
else{
NSString *errorString = [[error userInfo] objectForKey:@"error"];
[self showErrorView:errorString];
}
} progressBlock:^(int percentDone) {
}];
}
一段时间后,调试器出现错误:Error: invalid type for key image, expected map, but got file (Code: 111, Version: 1.2.15)
我一直在Parse文档中搜索,但没有关于这个问题的线索。
答案 0 :(得分:1)
您必须为列选择错误的类型。将其更改为文件类型。
NSData *imageData = UIImagePNGRepresentation(YourImageView.image);
PFFile *imageFile = [PFFile fileWithData:imageData];
[userObject setObject:imageFile forKey:@"YOUR_KEY"];
[userObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(succeeded)
{
NSLog(@"Object saved");
}else
{
NSLog(@"Error : %@",error);
}
}];