gpt4 book ai didi

ios - 使用来自包含 block 的两个方法的信息删除 UITableViewRows

转载 作者:行者123 更新时间:2023-11-28 22:11:53 25 4
gpt4 key购买 nike

我使用 AFNetworking2 和两种方法首先删除一行,然后获取更新的对象数组:

    [self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
NSDictionary * dict = [rapportsArray objectAtIndex:indexPath.row];
[self deleteRapportWithID:[dict objectForKey:@"id"]];
[self getRapports:interval];
[self.tableView endUpdates];;

正如您从这里看到的,所讨论的方法是 deleteRapport 和 getRapports,如前所述 - 两者都包含成功和失败 block ,成功时 getRapports 将更新 TableView 。

我的意图是使用 dispatch_async 等待两个方法都执行完,你能帮我提供一些实现方法的建议吗?

最佳答案

查看 dispatch_groups,您可以将 dispatch_group 绑定(bind)到 dispatch_queue 并在组中的所有项目都使用 完成时收到通知>dispatch_group_wait,即使您将异步调度到队列。

看看:

http://cocoasamurai.blogspot.com/2011/02/practical-design-patterns-with-blocks.html

总结:

dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_group_async(group, queue, ^{
... do some stuff ...
});

dispatch_group_async(group, queue, ^{
... do some other stuff ...
});

// wait until those async functions are done
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);

... continue doing stuff ...

关于ios - 使用来自包含 block 的两个方法的信息删除 UITableViewRows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22719512/

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