我上mapkit應用程序,它(末尾代碼)滴上一定位置的地圖上銷指定
我加代碼標註工作哪個calloutAccessoryControlTapped被調用。然而,取決於哪個引腳被竊聽,我試圖加載不同的視圖,我沒有找到任何奇怪的方式。
我放置了一個斷點,同時通過我注意到有一行讀取。 "[email protected]"myhome";
所以我想知道如果有方法我可以說什麼來調用取決於哪些註釋被點擊。
感謝
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString *identifier = @"myAnnotation";
MKPinAnnotationView * annotationView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.pinColor = MKPinAnnotationColorRed;
annotationView.animatesDrop = YES;
annotationView.canShowCallout = YES;
}else {
annotationView.annotation = annotation;
}
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return annotationView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
NSLog(@"Callout Tapped");
}
--Updated代碼
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// NSLog(annotation);
static NSString *identifier = @"myAnnotation";
MKPinAnnotationView * annotationView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.pinColor = MKPinAnnotationColorRed;
annotationView.animatesDrop = YES;
annotationView.canShowCallout = YES;
}else {
annotationView.annotation = annotation;
}
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return annotationView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
// MKUserLocation *ann = (MKUserLocation *)view.annotation;
// NSLog(@"ann.title = %@", ann.title);
NSLog(@"HJ");
}
}
在'calloutAccessoryControlTapped',這被竊聽的註釋是可以直接使用'view.annotation'。例如:'NSLog(@「Callout Tapped,title =%@」,view.annotation.title);'。見http://stackoverflow.com/questions/4565197/how-to-find-which-annotation-send-showdetails,http://stackoverflow.com/questions/22572342/how-to-access-to-an-annotation -attribute-inside-method-calloutaccessorycontrolta等 – Anna
@Anna我已經看過代碼。嘗試實施它。我仍然無法得到它太工作,你。我點擊揭密按鈕,它不運行if語句,好像在說[if([annotation isKindOfClass:[MKPointAnnotation class]])不計算爲真 –
@Anna明白了。沒有注意到我正在將MKPointAnnotation和MapAnnotation(我的類)混合起來 –