Ok, entonces estoy teniendo este problema Lo que quiero hacer es agregar manualmente varias anotaciones a un mapa. Cuando agrego solo una anotación, funciona sin problemas. El pin se cae, puede hacer clic en él para ver su rótulo, la vida es buena.
El problema viene cuando quiero agregar más de uno. Cuando agrego el segundo, de repente los pines no están coloreados correctamente (es decir, dependiendo de su magnitud deben ser de un cierto color, pero ahora son los dos iguales ...), y más importante cuando se hace clic en ellos, para ver su llamada, la aplicación se bloquea con exex_bad_access. Realmente no tengo idea de lo que está mal, ¿tal vez estoy agregando demasiadas vistas al mapa? Pero son solo 9 pines y los pines en sí mismos se agregan bien. Aquí está mi código ...
- (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;
}
incluso intentó eliminar la segunda función, pero no hizo nada.
¡Gracias por la ayuda! PD: También debería agregar, generalmente hay uno o dos pines de los 9 que funcionan cuando haces clic en la anotación ...
Si incluso intento manualmente anotar dos anotaciones a mano en el programa (es decir, eliminar el ciclo), sigue fallando y el color sigue siendo incorrecto ...













