我刚开始解析并尝试创建一个将用户链接到他/她的图片的PFRelation。这是我的代码:
NSData *imageData = UIImagePNGRepresentation(myImage);
PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
PFObject *pic = [PFObject objectWithClassName:@"Pics"];
//[pic setObject:imageFile forKey:@"Image"];
pic[@"Image"] = imageFile;
PFUser *user = [PFUser currentUser];
PFRelation *relation = [user relationForKey:@"myPhotos"];
[relation addObject:pic];
[user saveInBackground];
//[pic saveInBackground];
NSString * storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainScreen"];
[self presentViewController:myViewController animated:YES completion:nil];我知道图片本身是在保存,因为当我让图片保存在背景中时,当我单击Pic类时,它会显示我拍摄的图片。但是,我的问题是,当我查看User类时,当我单击myPhotos关系时,该关系中没有对象。为什么我的形象不被添加到关系中?
发布于 2015-04-03 06:31:14
PFObject *details = PFObject objectWithClassName:@"**your table name*“;NSData *imageData = UIImagePNGRepresentation(myImage);PFObject *picDetails = PFObject objectWithClassName:@@”**myphotos**“;picDetails @”图片“= UIImage imagewithdata:imageData;Details保存;picDetails保存;FRelation *relation = Details PFObject:@@”**myphotos**“;关系addObject:details;[详细信息保存saveInBackgroundWithBlock:^(BOOL成功,NSError *error) {//在上次保存后执行某些操作.如果(成功){ //对象已被保存。UIAlertView *success_alert = [UIAlertView allocinitWithTitle:@“成功”消息:@“成功图像保存”委托: success_alert:@“OK”otherButtonTitles: nil];success_alert显示;}{ //有一个问题,请检查error.description UIAlertView *fail_alert = [UIAlertView allocinitWithTitle:@"Failed“消息:@”未能保存数据“委托:self:@”OK“otherButtonTitles: 0];fail_alert show;}]; 这是使用图像保存在PFRelation中存储的方法。我希望这个答案能对你有所帮助。谢谢。
https://stackoverflow.com/questions/29402735
复制相似问题