我需要在解析NULL中创建一个值,这段代码不起作用

时间:2016-04-11 17:46:37

标签: ios objective-c parse-platform

我正在尝试使用背景图像设置器删除存储在解析中的图像并将其设置为null。它的工作方式是它在解析中查看一个单元格,如果它是未定义的,那么它给背景提供默认值,但如果它有一个值,那么它将它作为存储在该单元格中的文件加载...怎么能我调整这段代码,使其在解析时在单元格中放置一个空值?  user[PF_USER_BACKGROUND]需要设置为undefined(已删除值)

 //-------------------------------------------------------------------------------------------------------------------------------------------------
    - (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"];

    }

1 个答案:

答案 0 :(得分:1)

你尝试过这样的事吗?

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

    user[PF_USER_BACKGROUND] = nil;

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

如果user禁止nil值,则可能必须使用[NSNull null]