Ok, je suis tellement avoir ce problème. Ce que je veux faire est d'ajouter manuellement plusieurs annotations à une carte. Quand je viens d'ajouter une annotation, il fonctionne parfaitement. Les gouttes de broches, vous pouvez cliquer dessus pour voir sa légende, la vie est bonne.
Le problème vient quand je veux ajouter plus d'un. Quand j'ajoute le second, tout à coup de la broche ne sont pas correctement colorés (c.-à-selon leur importance, ils devraient être une certaine couleur, mais ils sont maintenant à la fois la même ...), et surtout lorsque vous cliquez dessus, pour voir leur callout, l'application se bloque avec exex_bad_access. Je ne sais vraiment pas ce qui ne va pas, peut-être j'ajouter trop de vues à la carte? Mais il est seulement 9 broches et les broches s'ajouter très bien. Voici mon 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;
}
même essayé d'enlever la deuxième fonction, mais il n'a rien fait.
Merci pour l'aide! PS Je dois aussi ajouter, il y a habituellement une ou deux broches des 9 qui fonctionne lorsque vous cliquez sur l'annotation ...
Si je tente même que deux annotations à la main manuellement dans le programme (c.-à enlever la boucle), il échoue encore et la couleur est encore mal ...













