我为我的自定义注释制作了这些代码:
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.delegate=self;
[self AddLocations];
[self initiateMap];
......
这是我的 addLocation 函数:
-(id<MKAnnotation>)addAnnotationWithTitle: (NSString*) title coordinate:(CLLocationCoordinate2D)
Location imageName:(NSString*) imageName{
CustomAnnotation *annotation = [[CustomAnnotation alloc]init];
annotation.title = title;
annotation.subtitle = @"This is a subtitle";
[annotation setCoordinate:Location];
annotation.imageName = imageName;
return annotation;
}
和我的 CustomAnnotation 类:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
NSLog(@"Test");
if([annotation isKindOfClass:[MKUserLocation class]]){
return nil;
}
if([annotation isKindOfClass:[CustomAnnotation class]]){
CustomAnnotation *customAnnotation = annotation;
static NSString* annotationid = @"Annotation";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:annotationid];
if(!annotationView){
annotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationid];
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}else{
annotationView.annotation = annotation;
}
annotationView.image = [UIImage imageNamed:customAnnotation.imageName];
return annotationView;
}
return nil;
}
由于某种原因,从未使用 viewForAnnotation 函数。有谁可以帮我离开这里吗?谢谢