Sia*_*Alp 3 objective-c ios parse-platform
我有表名"事件".在该表中,我有一个string类型的列.我正在努力解决如何从该列中仅删除一个元素的问题.考虑下面的图像,我想从"usersIncluded"列中删除所有出现的"iYYeR2a2rU",而不删除行.我用过了removeObject:(id) forKey:(NSString *)它并没有用.

这就是我试图实现它的方式:
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"];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
这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];
}];
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
3548 次 |
| 最近记录: |