MKAnnotationView viewForAnnotation never called
after i spend 2 days of searching the bug i have to ask for help here. i do have MapViewController and place some pins on the map. i´ve copied most of the code from MapCallouts and WeatherMap of the apple code samples.
anyhow it seems that i´ve deleted or missed essential parts. it seems there is no connection between the MapViewController and the following code
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(@"MKAnnotationView");
return nil;
}
setting an annotation looks like this and it works well:
- (void)createPoi:(CLLocationCoordinate2D)theCoordinate
{
NSLog(@"createPoi");
RandomAnnotation *randomAnnotation = [[RandomAnnotation alloc] init];
[randomAnnotation setTheCoordinate:theCoordinate];
[randomAnnota开发者_Python百科tion setTheTitle:@"bla"];
[randomAnnotation setTheSubTitle:@"bla"];
[self.mapAnnotations insertObject:randomAnnotation atIndex:kRandomAnnotationIndex];
[randomAnnotation release];
[self.mapView addAnnotation:[self.mapAnnotations objectAtIndex:kRandomAnnotationIndex]];
}
i can´t figure out what's wrong. could anybody give me a hint what´s missing? i have to admit that i don´t have any experience with the delegate pattern.
Make sure the map view's delegate
property is set.
If the map is created in IB, right-click on it and hook up its delegate outlet to File's Owner.
If the map is created in code, set the delegate after creating the map view:
mapView.delegate = self;
In the .h where your MKMapView is declared and where your declare viewForAnnotation method, be sure to add MKMapViewDelegate in the list of protocols your class should include :
@interface myViewController : UIViewController <MKMapViewDelegate> {
MKMapView *_mapView;
}
Then in the viewDidLoad method, be sure to to add
_mapView.delegate = self;
You can also assign the delegate of the mapView in interface builder if you've done things using it !
精彩评论