マップ ビューにいくつかのマップ ピンを表示しています。注釈に触れたときに吹き出しが表示されない理由がわかりません。これが私のコードです。カテゴリ ID に応じて異なるピン画像を表示するために、viewDidLoad メソッドにいくつかの条件付きコードがあります。カスタム ピンは正しく表示されますが、それらに触れても何も起こりません。
これを手伝ってくれてありがとう。
- (void)viewDidLoad {
[super viewDidLoad];
[self requestData];
CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(44.2632, 11.4403);
MKCoordinateSpan span;
span.latitudeDelta=5;
span.longitudeDelta=5;
MKCoordinateRegion ITRegion = MKCoordinateRegionMake(centerCoord, span);
ITRegion.span=span;
[mapView setRegion: ITRegion animated: YES];
mapView.delegate=self;
[self.mapView setShowsUserLocation:YES];
for (int i=0; i<[publicDataArray count]; i++) {
MKPointAnnotation* annotation= [MKPointAnnotation new];
CLLocationCoordinate2D coordinate;
coordinate.latitude = [[[[publicDataArray objectAtIndex:i] objectForKey:@"address"] objectForKey:@"lat"] doubleValue];
coordinate.longitude = [[[[publicDataArray objectAtIndex:i] objectForKey:@"address"] objectForKey:@"lng"] doubleValue];
NSString *catId = [NSString stringWithFormat:@"%@",[[publicDataArray objectAtIndex:i] objectForKey:@"category_id"]];
if ([catId isEqual: @"213"]) {
annView.image = [UIImage imageNamed:@"comprareMap.png"];//sets image for pin
} else if ([catId isEqual:@"217"]) {
annView.image = [UIImage imageNamed:@"vedereMap.png"];//sets image for pin
} else if ([catId isEqual:@"221"]) {
annView.image = [UIImage imageNamed:@"mangiareMap.png"];//sets image for pin
}
annotation.coordinate = coordinate;
[mapView addAnnotation: annotation];
}
}
- (MKAnnotationView *) mapView:(MKMapView *)mapingView viewForAnnotation:(id <MKAnnotation>) annotation {
annView = nil;
if(annotation != mapingView.userLocation)
{
static NSString *defaultPinID = @"";
annView = (MKAnnotationView *)[mapingView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( annView == nil )
annView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] ;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = rightButton;
annView.canShowCallout = YES;
}
return annView;
}