我已经用MKPinAnnotationView
图片替换了红色别针
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *annotationView=[mapView dequeueReusableAnnotationViewWithIdentifier:parkingAnnotationIdentifier];
//If one isn’t available, create a new one
if(!annotationView){
annotationView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:parkingAnnotationIdentifier];
//Here’s where the magic happens
annotationView.image=[UIImage imageNamed:@"dot.png"];
}
return annotationView;
}
现在,当我单击任何按钮时,我有一个详细信息披露,它将转到该注释的详细页面。
到这里为止还好。现在的问题是,当我再次从详细信息页面返回地图视图时,会出现默认的红色图钉而不是 dot.png,因为第一次加载视图时-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
会调用此方法,但是当我们从详细信息返回时页面视图将出现没有被调用。如何解决这个问题?
if ([list_array count]>0) {
location1.latitude = [[[list_array objectAtIndex:0]valueForKey:@"latitude"]floatValue];
location1.longitude = [[[list_array objectAtIndex:0]valueForKey:@"longitude"]floatValue];
region.center = location1;
if ([[list_array objectAtIndex:0]valueForKey:@"company_id"]) {
for (int i=0; i<[list_array count]; i++)
{
CLLocationCoordinate2D location1;
location1.latitude = [[[list_array objectAtIndex:i]valueForKey:@"latitude"]floatValue];
location1.longitude = [[[list_array objectAtIndex:i]valueForKey:@"longitude"]floatValue];
region.span = span;
BasicMapAnnotation *addAnnotation1 = [[BasicMapAnnotation alloc] initWithLatitude:location1.latitude andLongitude:location1.longitude] ;
addAnnotation1.tag = i;
[mapView addAnnotation:addAnnotation1];
}
}
}
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
//[self.view addSubview:self.mapView];