Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 指定调用了哪个calloutAccessoryControlTapped_Objective C_Mapkit - Fatal编程技术网

Objective c 指定调用了哪个calloutAccessoryControlTapped

Objective c 指定调用了哪个calloutAccessoryControlTapped,objective-c,mapkit,Objective C,Mapkit,我正在开发一个mapkit应用程序,它会在地图上的某些位置的末尾添加图钉代码 我还为标注添加了代码。然而,根据哪个引脚被点击,我试图加载一个不同的视图,我没有找到任何奇怪的方法 我放置了一个断点,当我跨过这个断点时,我注意到有一行是这样读的。 annotation.title=@myhome;所以我想知道是否有什么方法可以根据点击的注释说出调用什么 谢谢 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(i

我正在开发一个mapkit应用程序,它会在地图上的某些位置的末尾添加图钉代码

我还为标注添加了代码。然而,根据哪个引脚被点击,我试图加载一个不同的视图,我没有找到任何奇怪的方法

我放置了一个断点,当我跨过这个断点时,我注意到有一行是这样读的。 annotation.title=@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");
}
-更新代码

您可以将标签设置为1表示左侧,2表示右侧附件视图。在calloutAccessoryControlTapped方法中,执行以下操作:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

    if ([control tag] == 1) {
        NSLog(@"tapped left accessory");
    }
    else if ([control tag] == 2) {
        NSLog(@"tapped right accessory");
    }
}

我会在设置注释标签等的代码中分配这个标记?我的MapAnnotation*myhome=[[MapAnnotation alloc]init];在Callout AccessoryControlTapped中似乎没有setTag方法,使用view.annotation可以直接访问所点击的注释。例如:NSLog@Callout点击,标题=%@,视图。注释。标题;。看,等等。@Anna我已经看过密码了。我试着实现它。我还是不能得到它太多的工作。我单击“披露者”按钮,它不会运行if语句,好像在说[annotation isKindOfClass:[MKPointAnnotation class]]的计算结果不是true@Anna知道了。我没注意到我把MKPointAnnotation和我的MapAnnotation类混在一起了
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

    if ([control tag] == 1) {
        NSLog(@"tapped left accessory");
    }
    else if ([control tag] == 2) {
        NSLog(@"tapped right accessory");
    }
}