我遇到了从后台作业返回主线程以使 UI 更新为MapKit
的问题。最底层的代码片段是我试图返回主队列进行更新的方式,虽然这确实有效,但是有一个非常大的延迟(至少20-35秒)。顶部代码段只删除了dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
完美运作(但阻止)
annotation *customAnnotationClass =[[customAnnotationClass alloc] initWithCoordinate:CLLocationCoordinate2DMake( [lat doubleValue], [lng doubleValue])];
[annotation createAnnotationView];
self.myAnnotations=[NSArray arrayWithObjects:annotation, nil];
dispatch_async(dispatch_get_main_queue(), ^{
[_myMapView addAnnotations:_myAnnotations];
});
}
实际将注释更新到地图上的延迟时间很长(10-15秒)。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
annotation *customAnnotationClass =[[customAnnotationClass alloc] initWithCoordinate:CLLocationCoordinate2DMake( [lat doubleValue], [lng doubleValue])];
[annotation createAnnotationView];
self.myAnnotations=[NSArray arrayWithObjects:annotation, nil];
dispatch_async(dispatch_get_main_queue(), ^{
[_myMapView addAnnotations:_myAnnotations];
});
}
});
有什么想法我如何成功返回主线程并进行UI
更新?