好的,所以我遇到了这个问题。我想要做的是手动添加多个注释到地图。当我只添加一个注释时,它完美地工作。销滴,你可以点击它看到它的标注,生活是美好的。将多个注释添加到地图时出现问题
问题来了,当我想添加多个。当我添加第二个时,突然针的着色不正确(即取决于它们的大小,它们应该是某种颜色,但它们现在都是相同的......),更重要的是当你点击它们时,看到它们标注,该应用程序崩溃与exex_bad_access。我真的不知道什么是错的,也许我在地图上添加了太多的视图?但它只有9个引脚,引脚本身也很好。 这里是我的代码...
- (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;
}
甚至试图消除第二个功能,但它没有做任何事情。
感谢您的帮助! PS我也应该补充一点,通常有一个或两个针脚出现在9中,当你点击注释时它会起作用...
如果我甚至尝试在程序中手工操作两个注释(即删除循环) ,它仍然失败,颜色仍然是错误的...
另外,我要补充的是,如果我手动两个注解添加到地图上,以同样的方式的东西崩溃。 总线BUS2 * = [BUS1 initWithStop:[停止objectAtIndex:0]; MapAnnotation * eqAnn = [MapAnnotation annotationWithBus:BUS2]; [self.mapView addAnnotation:eqAnn]; 总线BUS2 * = [BUS1 initWithStop:停止objectAtIndex:1]; MapAnnotation * eqAnn = [MapAnnotation annotationWithBus:bus2]; [self.mapView addAnnotation:eqA NN]; 这仍然失败。 – kodai 2009-08-17 18:53:07