Ok, so habe ich dieses Problem. Was ich tun möchte, ist manuell mehrere Anmerkungen zu einer Karte hinzufügen. Wenn ich nur eine Anmerkung hinzufügen, funktioniert es einwandfrei. Der Pin-Tropfen, können Sie darauf klicken, seine Legende zu sehen, das Leben ist gut.
Das Problem kommt, wenn ich als eine weitere hinzufügen möchten. Als ich den zweiten hinzufügen, plötzlich die stecknadel nicht richtig gefärbt (dh auf ihrer Größe abhängig, bei dem sie eine bestimmte Farbe geben, aber sie sind beide jetzt die gleichen ...), und was noch wichtiger ist, wenn Sie darauf klicken, um zu sehen, ihre callout, stürzt die App mit exex_bad_access. Ich habe wirklich keine Ahnung, was los ist, vielleicht ich hinzufüge, zu viele Ansichten auf die Karte? Aber es ist nur 9 Pins und die Stifte sich fügen Sie einfach in Ordnung. 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 möchte auch hinzufügen, gibt es in der Regel ein oder zwei Stifte aus der 9, die funktioniert, wenn Sie die Anmerkung klicken ...
Wenn ich von Hand manuell nur zwei Anmerkungen versucht auch im Programm (dh entfernen Sie die Schleife), scheitert es immer noch, und die Farbe ist immer noch falsch ...













