iPhone - PFRelation не сохраняет объект

Я новичок в анализе и пытаюсь создать 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, в этом отношении нет объектов. Почему мои изображения не будут добавлены в отношение?


person user2779450    schedule 01.04.2015    source источник


Ответы (1)


PFObject *details = [PFObject objectWithClassName:@"**your table name**"];

NSData *imageData = UIImagePNGRepresentation(myImage);

PFObject *picDetails = [PFObject objectWithClassName:@"**myphotos**”];

picDetails [@"picture"] = [UIImage imagewithdata:imageData];
                     [Details save];  [picDetails save];
                          FRelation *relation = [Details relationForKey:@"**myphotos**"];  [relation addObject:details];
                            [Details saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                                //Do something after the last save...

                                if (succeeded) {
                                    // The object has been saved.
                                    UIAlertView *success_alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Successfully image saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                                    [success_alert show];

                                } else {
                                    // There was a problem, check error.description
                                    UIAlertView *fail_alert = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to save data" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                                    [fail_alert show];
                                }
                            }];

Это способ сохранения в PFRelation с использованием сохранения изображения. Я надеюсь, что этот ответ может помочь вам. Спасибо.

person Senthil    schedule 03.04.2015