我需要对MKDirections
(10)做多次请求,我希望加快我的iOS7
应用。
10 calculateDirectionsWithCompletionHandler
之后,我想更新用户界面。
我尝试使用GCD
进行异步调用。
我的问题是,GCD
我不知道如何在更新用户界面之前等待所有calculateDirectionsWithCompletionHandler
的结束。
这是我的代码:
dispatch_group_t taskGroup = dispatch_group_create();
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_group_async(taskGroup, mainQueue, ^{
[directions1 calculateDirectionsWithCompletionHandler:
^(MKDirectionsResponse *response, NSError *error) {...}];
});
.........
dispatch_group_async(taskGroup, mainQueue, ^{
[directions10 calculateDirectionsWithCompletionHandler:
^(MKDirectionsResponse *response, NSError *error) {...}];
});
/* Update UI */
dispatch_group_notify(taskGroup, mainQueue, ^{
/* Do some processing here and UI Update */
});
问题是UI在所有calculateDirectionsWithCompletionHandler
!
为什么呢? 我的代码中存在哪个问题?
感谢您的帮助。