gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 06:23:13 26 4
gpt4 key购买 nike

我有表名“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com