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];