我有很多注释要添加到 mkmapview 中。当我添加注释时,应用程序会冻结一小段时间。我知道主线程是唯一允许添加 UI 以查看的线程,如果这是真的,我如何使这个操作不冻结应用程序?
// in viewdidLoad
for (NSManagedObject *object in requestResults) {
CustomAnnotation *customAnnotation = [[CustomAnnotation alloc] init];
customAnnotation.title = object.title;
customAnnotation.coordinate = CLLocationCoordinate2DMake([object.latitude doubleValue], [object.longitude doubleValue]);
[_mapView addAnnotation:customAnnotation];
}
} // end viewdidload
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
// shows the annotation with a custom image
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"mapAnnotation"];
CustomAnnotation *customAnnotation = (id) annotation;
customPinView.image = [UIImage imageNamed:@"green"];
return customPinView;
}