我正在我的 iPad 应用程序中实现一个功能,以显示一个带有自定义注释的地图视图。出于某种原因, - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id ) 注释方法在地图加载后 1-2 秒被调用,我认为这是很多时间。
问题是,如果您在图钉加载之前从地图视图导航到另一个视图,则应用程序会因访问错误而崩溃。因此,我认为这 1-2 秒的延迟不应该存在。
没有什么特别的事情发生,只有几 (3) 个引脚可以显示,所以这不应该是性能问题。
如果您对此有解决方案,请告诉我。
编码:
MAPVIEW控制器
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self setTitle:self.pageTitle];
[self.navigationController.navigationBar setTintColor:[UIColor lloydsNavBarTintColour]];
[self.mapView setDelegate:self];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 53.566414;
region.center.longitude = -0.922852;
region.span.longitudeDelta = 10.0f;
region.span.latitudeDelta = 10.0f;
[self.mapView setRegion:region animated:YES];
ACNEfficiencyAnnotation *annotation = [[ACNEfficiencyAnnotation alloc]init];
[annotation setCoordinate:CLLocationCoordinate2DMake(55.5783462524414,-4.39453077316284)];
[self.mapView addAnnotation:annotation];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
self.annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
return self.annotationView;
}
注释实现:
@interface ACNEfficiencyAnnotation : NSObject <MKAnnotation>
{
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, strong) ACNEfficiencyLocation *location;
@end
@implementation ACNEfficiencyAnnotation
@synthesize coordinate;
@synthesize title;
@synthesize subtitle;
@synthesize location;
@end