gpt4 book ai didi

ios - 在 for 循环中完成 findObjectsInBackgroundWithBlock 后执行操作

转载 作者:行者123 更新时间:2023-11-28 19:01:23 24 4
gpt4 key购买 nike

我的代码中有这样的结构:

for (METMeetingEntity *e in self.meetingList) {
PFQuery *query = [PFUser query];
//some query constraints, depending on METMeetingEntity
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
// some query actions


NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES]];
self.meetingList = [NSMutableArray arrayWithArray:[self.meetingList sortedArrayUsingDescriptors:sortDescriptors]];
self.meetingList = [self dateCleanup:self.meetingList];
}];

我如何执行操作 - 在所有 findObjectsInBackground 完成后重新加载我的 TableView

最佳答案

一个可能的解决方案是保持计数。当数字与原始计数相符时,您就知道自己完成了。

NSUInteger count = self.meetingList.count;
for (METMeetingEntity *e in self.meetingList) {
PFQuery *query = [PFUser query];
//some query constraints, depending on METMeetingEntity
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// some query actions
NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES]];
self.meetingList = [NSMutableArray arrayWithArray:[self.meetingList sortedArrayUsingDescriptors:sortDescriptors]];
self.meetingList = [self dateCleanup:self.meetingList];

count--;
if (count == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
// reload table or whatever needs to be done
});
}
}];
}

关于ios - 在 for 循环中完成 findObjectsInBackgroundWithBlock 后执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24999986/

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