Ok, ich habe dieses Problem. Ich möchte manuell mehrere Annotationen zu einer Map hinzufügen. Wenn ich nur eine Anmerkung hinzufüge, funktioniert es einwandfrei. Die Nadel fällt, du kannst sie anklicken, um ihre Legende zu sehen, das Leben ist gut.Problem beim Hinzufügen mehrerer Anmerkungen zur Karte
Das Problem kommt, wenn ich mehr als eins hinzufügen möchte. Wenn ich die zweite hinzufüge, sind die Pins plötzlich nicht mehr richtig gefärbt (dh abhängig von ihrer Größe sollten sie eine bestimmte Farbe haben, aber jetzt sind sie beide gleich ...) und, noch wichtiger, wenn du darauf klickst, um ihre zu sehen Callout, stürzt die App mit exex_bad_access ab. Ich habe wirklich keine Ahnung, was los ist, vielleicht füge ich der Karte zu viele Ansichten hinzu? Aber es sind nur 9 Pins und die Pins selbst fügen sich gut. Hier ist mein Code ...
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *stops = [[NSMutableArray alloc] init]; //Get list of all the stops available
Bus *bus1 = [[Bus alloc] init]; // Bus 1 holds the stops
stops = [bus1 returnStops];
for (NSString *stop in stops) //Go through each stop to add annotation to map
{
Bus *bus2 = [bus1 initWithStop:stop]; //Create an instance of bus with a given stop
MapAnnotation *eqAnn = [MapAnnotation annotationWithBus:bus2];
[self.mapView addAnnotation:eqAnn]; //Add the annotation to the map
//[eqAnn release];
//[bus2 release];
}
[self recenterMap];
[stops release];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *view = nil;
if(annotation != mapView.userLocation) {
MapAnnotation *eqAnn = (MapAnnotation*)annotation;
view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"busLoc"];
if(nil == view) {
view = [[[MKPinAnnotationView alloc] initWithAnnotation:eqAnn
reuseIdentifier:@"busLoc"] autorelease];
}
CGFloat magnituide = [eqAnn.bus.magnitude floatValue];
if(magnituide >= .80f) {
[(MKPinAnnotationView *)view setPinColor:MKPinAnnotationColorRed];
} else if(magnituide >= .60f) {
[(MKPinAnnotationView *)view setPinColor:MKPinAnnotationColorPurple];
} else
{
[(MKPinAnnotationView *)view setPinColor:MKPinAnnotationColorGreen];
}
[(MKPinAnnotationView *)view setAnimatesDrop:YES];
[view setCanShowCallout:YES];
}
return view;
}
sogar versucht, die zweite Funktion zu entfernen, aber es hat nichts getan.
Danke für die Hilfe! PS Ich sollte auch hinzufügen, es gibt in der Regel eine oder zwei Pins aus der 9, die funktioniert, wenn Sie auf die Annotation klicken ...
Wenn ich sogar manuell nur zwei Anmerkungen manuell im Programm versuchen (dh, entfernen Sie die Schleife) , es schlägt immer noch fehl und die Farbe ist immer noch falsch ...
Auch sollte ich hinzufügen, dass, wenn ich hinzufügen, zwei Anmerkungen zu der Karte manuell, das Ding stürzt auf die gleiche Weise. Bus * bus2 = [bus1 initWithStop: [stoppt objectAtIndex: 0]; MapAnnotation * eqAnn = [MapAnnotation annotationWithBus: bus2]; [self.mapView AddAnnotation: eqAnn]; Bus * bus2 = [bus1 initWithStop: [Anschläge objectAtIndex: 1]; MapAnnotation * eqAnn = [MapAnnotierung annotationWithBus: bus2]; [self.mapView addAnnotation: eqA nn]; Dies schlägt immer noch fehl. – kodai