Travis Tubbs
Travis Tubbs

Reputation: 877

I need to make a value in parse NULL and this code does not work

I am trying to have a background image setter that removes the image stored in parse and sets it to null. The way it works is that it looks at a cell in parse and if it is undefined then it gives the background the default value, but then if it has a value then it loads it as the file stored in that cell... How can I tweak this code to make it place a null value in the cell on parse? user[PF_USER_BACKGROUND] needs to be set to undefined (value removed)

 //-------------------------------------------------------------------------------------------------------------------------------------------------
    - (void)actionSetDefaultBackground
    //-------------------------------------------------------------------------------------------------------------------------------------------------
    {
        UIImage *picture = nil;
        PFFile *fileBackground = [PFFile fileWithName:@"background.jpg" data:UIImageJPEGRepresentation(picture, 0.6)];
        [fileBackground saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
         {

             if (error == nil)
             {
                 PFUser *user = [PFUser currentUser];

                 user[PF_USER_BACKGROUND] = fileBackground.url;
                 [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
                  {
                      if (error != nil) [ProgressHUD showError:@"Network error."];
                  }];
             }
             else [ProgressHUD showError:@"Network error."];
             NSLog(@"uploaded Background");

         }];
        self.view.backgroundColor = [UIColor colorWithPatternImage:picture];
        self.collectionView.backgroundColor = [UIColor clearColor];
        tag = @"message";
        [ProgressHUD showSuccess:@"Chat Background Set"];

    }

Upvotes: 0

Views: 93

Answers (1)

aednichols
aednichols

Reputation: 2322

Have you tried something like this?

- (void)removeUserImage
{
    PFUser *user = [PFUser currentUser];

    user[PF_USER_BACKGROUND] = nil;

    [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error != nil) [ProgressHUD showError:@"Network error."];
    }];
}

If user forbids nil values, you may have to use [NSNull null].

Upvotes: 1

Related Questions