Ich versuche, eine ziemlich geradlinige benutzerdefinierte Karte Annotation Ansicht und Callout zu verwenden - die Annotation Ansicht, wenn ich es erstellen, fügt nur eine UIImageView als Unteransicht zu sich selbst. Das funktioniert gut.
Allerdings, wenn ich canShowCallout auf die Annotation Ansicht aufrufen, Eine Ausnahme wird in MapKit sofort nach der Rückkehr der Ansicht ausgelöst. Das Ende des Stacks sieht wie folgt aus:
#0 0x94e964e6 in objc_exception_throw
#1 0x01e26404 in -[MKOverlayView _addViewForAnnotation:]
#2 0x01e22037 in -[MKOverlayView _addViewsForAnnotations:animated:]
#3 0x01e1ddf9 in -[MKOverlayView showAddedAnnotationsAnimated:]
#4 0x01df9c0e in -[MKMapView _showAddedAnnotationsAndRouteAnimated:]
#5 0x01e0371a in -[MKMapView levelView:didLoadTile:]
Meine viewForAnnotation ist ziemlich einfach:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ( ! [annotation isKindOfClass:[MyAnnotation class]] )
return nil;
MyAnnotationView *useView = (MyAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:@"resuseview"];
if ( useView == nil )
{
useView = [[[MyAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"resuseview"] autorelease];
useView.canShowCallout = YES; // if commented out view appears just fine
}
else
{ useView.annotation = annotation; }
return useView;
}
Wie im Code erwähnt, funktioniert die Anmerkungsansicht gut, wie es ist - bis ich canShowCallout hinzufügen, dann stürzt es das erste Mal die Karte erhält die Ansicht.