ios - 从 Parse (iOS SDK) 中的列类型的数组中删除一个项目

标签 ios objective-c parse-platform

我有表名“Events”。在该表中,我有一列字符串数组类型。我正在努力解决如何从该列中只删除一个元素的问题。考虑下图,我想从“usersIncluded”列中删除所有出现的“iYYeR2a2rU”,而不删除行。 我使用了 removeObject:(id) forKey:(NSString *) 但它没有用。

image

这就是我试图实现它的方式:

  PFQuery *query = [PFQuery queryWithClassName:@"Events"];
    NSArray *eventObjects = [query findObjects];
    [query whereKey:@"usersIncluded" equalTo:[self.uniqeFriendList objectAtIndex:indexPath.row]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
        for (int i = 0; i<objects.count; i++) {
            PFObject *event = [eventObjects objectAtIndex:i];
            [event removeObject:[self.uniqeFriendList objectAtIndex:indexPath.row] forKey:@"usersIncluded"];
        }
    }];
}

self.uniqeFriendList 是一个可变数组,其中包含我要从“usersIncluded”列中删除的 ID。

提前致谢

最佳答案

我认为您使用的是正确的方法(removeObject:forKey: 应该完全按照您的要求执行),但我认为您正在使用错误数组中的对象。您执行了两次查询,并且在 findObjectsInBackgroundWithBlock: 中,您正在使用第一次调用数组时的数组...试试这个:

PFQuery *query = [PFQuery queryWithClassName:@"Events"];
[query whereKey:@"usersIncluded" equalTo:[self.uniqeFriendList objectAtIndex:indexPath.row]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
    for (int i = 0; i <objects.count; i++) {
        PFObject *event = [objects objectAtIndex:i];    // note using 'objects', not 'eventObjects'
        [event removeObject:[self.uniqeFriendList objectAtIndex:indexPath.row] forKey:@"usersIncluded"];
    }

    [PFObject saveAll:objects];
}];

关于ios - 从 Parse (iOS SDK) 中的列类型的数组中删除一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21301356/

相关文章:

iphone - 将 NSURLConnection 绑定(bind)到特定接口(interface)

ios - Xcode 存档错误 : Missing IOS Distribution Signing Identity For (Name)

ios - 键盘隐藏后 UISearchDisplayController tableview 内容偏移量不正确

objective-c - ios mapkit 通过点击 map 关闭注释标注

iphone - 当我的手指移动时如何填充图像的透明区域

iphone - Xtify框架和ASI-HTTP请求重复符号

angularjs - DisableSingleInstance 模式下 Parse JS SDK 对象的 angular.copy 返回空对象

ios - 如何更改 UIButton : The signup button in Parse`s PFLoginViewController 的颜色

java - 错误〜parse.com推送通知android?

iphone - 弹出窗口内选择器 View 中的问题