我正在尝试使用背景图像设置器删除存储在解析中的图像并将其设置为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"];
}
答案 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]
。