I want to create custom callouts on my map. I've tried this right now -
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(@"ANNNOTATION VIEW : %@", view);
NSLog(@"VIEW ANNOTATION: %@", view.annotation);
MyMapAnnotationViewController* mapAnnotationViewController = [[MyMapAnnotationViewController alloc]initWithNibName:@"MapAnnotationView" bundle:nil];
MyLocation* location = (MyLocation*)view.annotation;
[mapAnnotationViewController setTitle: [location title]];
[mapAnnotationViewController setRating:3.0];
[view addSubview:mapAnnotationViewController.view];
}
-(void)viewWillAppear:(BOOL)animated{
[_mapView setRegion: _viewRegion];
for (id<MKAnnotation> annotation in _mapView.annotations) {
[_mapView removeAnnotation:annotation];
}
for(NSDictionary* result in _resultsToPlot){
NSString* address = someAddr;
NSString* restaurantTitle = someTitle;
NSString* description = someDescription;
NSString* lonLat = someLonLat;
NSArray *list = [lonLat componentsSeparatedByString:@";"];
CLLocationCoordinate2D coordinate;
coordinate.longitude = [[list objectAtIndex: 1] doubleValue];
coordinate.latitude = [[list objectAtIndex: 0] doubleValue];
MyLocation *annotation = [[MyLocation alloc] initWithName:restaurantTitle address:address coordinate:coordinate] ;
[_mapView addAnnotation:annotation];
}
MyLocation is a subclass of MKAnnotation.
However, this is what things look like now when I click -
So when I click on one pin, my custom view shows AND the annotation shows. I just want the custom view to show. Further, when I click on another pin, the previous custom views are still there.
How do I get it so that the annotation becomes my custom view?
OK - so I did the below and added this-
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(MKAnnotationView*)annotation{
annotation.canShowCallout = NO;
return annotation;
}
I am now getting this error-
NSInvalidArgumentException', reason: '-[MyLocation setCanShowCallout:]: unrecognized selector sent to instance 0xcb683e0'