更新PFObject的值 - iOS

时间:2014-07-07 22:31:21

标签: ios parse-platform

我试图让PFUser能够编辑他们创建的PFObject值。

目前,PFUserPFOBject类中创建ClientCreater

-(IBAction)New:(id)sender
{
    PFObject *New = [PFObject objectWithClassName:@"client"];
    PFUser *user = [PFUser currentUser];
    [New setObject:user.username forKey:@"username"];
    [New setObject:[[self Name] text] forKey:@"name"];
    [New setObject:[[self Team] text] forKey:@"team"];
    [New setObject:[[self Points] text] forKey:@"points"];
    [New setObject:[[self Height] text] forKey:@"height"];
    [New setObject:[[self Weight] text] forKey:@"weight"];
    [New setObject:[[self Position] text] forKey:@"position"];
    [New setObject:[[self Game] text] forKey:@"game"];
    [New setObject:[[self Hometown] text] forKey:@"hometown"];
    [New setObject:[[self Birthday] text] forKey:@"birthday"];
  //  [New setObject:[[self Bio] text] forKey:@"bio"];

    NSData *imageData = UIImageJPEGRepresentation(PlayerImage.image, 0.8);
    NSString *filename = [NSString stringWithFormat:@"%@.png", Name.text];
    PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
    [New setObject:imageFile forKey:@"imageFile"];

    [New saveInBackground];
    NSLog(@"Object Added");
}

这是我尝试检索PFObject类的viewDidLoad中的ClientEditController

PFQuery *query = [PFQuery queryWithClassName:@"client"];

    // BEFORE WE QUERY
       [query whereKey:@"user" equalTo:[PFUser currentUser]];


    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {

            // Get your objects here

            [objectt objectForKey:@"user"];

        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];

在.h我宣布了这个:

@property(nonatomic, strong) PFObject *objectt;

然后我在这里尝试为name更新PFUser的值:

-(IBAction)SaveObject:(id)sender
{

    [objectt setObject:Name.text forKey:@"name"];
    [objectt saveInBackground];

}

0 个答案:

没有答案