我在 IOS 中编写了一个程序,我在地图上用大头针标记了几个点。现在我有了 dequereusableannotationview 代码,它可以在一个引脚上正常工作,但在我使用两个引脚或尝试在地图上标记两个点时崩溃。它仅在我注释掉一个注释或注释掉 dequeucode 时才有效但问题是....我什至需要那个 dequeu 代码吗?因为我将拥有的最多的引脚可能是...10 ..?
谢谢
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
MKMapView *mv=[[MKMapView alloc]initWithFrame:CGRectZero];
mv.delegate=self;
[self setView:mv];
MapAnnotation* ann=[[MapAnnotation alloc]init];
CLLocationCoordinate2D location;
location.latitude=(double)51.501468;
location.longitude=(double)-0.141596;
[ann setCoordinate:location];
[ann setTitle:@"test"];
[ann setTitle:@"plz work"];
[mv addAnnotation:ann];
[ann release];
MapAnnotation* AnnB=[[MapAnnotation alloc]init];
CLLocationCoordinate2D locationB;
locationB.latitude=(double)16.4944;
locationB.longitude=(double)-151.7364;
[AnnB setCoordinate:locationB];
[AnnB setTitle:@"test"];
[AnnB setSubtitle:@"work"];
[mv addAnnotation:AnnB];
[AnnB release];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pinView=nil;
if (annotation!=mapView.userLocation) {
static NSString *defaultID=@"MYLoction";
pinView=(MKPinAnnotationView *)[mapView
dequeueReusableAnnotationViewWithIdentifier:defaultID];
if (pinView=nil) {
pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultID]autorelease];
pinView.pinColor=MKPinAnnotationColorPurple;
pinView.canShowCallout=YES;
pinView.animatesDrop=YES;
}
}
}