Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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
Iphone 如何在自定义MKAnnotationView中检测触摸?损失7_Iphone_Xcode_Map_Annotations_Mkmapview - Fatal编程技术网

Iphone 如何在自定义MKAnnotationView中检测触摸?损失7

Iphone 如何在自定义MKAnnotationView中检测触摸?损失7,iphone,xcode,map,annotations,mkmapview,Iphone,Xcode,Map,Annotations,Mkmapview,这行不通 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 试着加上这个 if ([annotation isKindOfClass:[User class]]) { NSString * annotationIdentifier = @"UserAnnota

这行不通

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
试着加上这个

  if ([annotation isKindOfClass:[User class]])
     {
         NSString * annotationIdentifier = @"UserAnnotationIdentifier";
         CustomAnnotationView * customAnnotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
         if (!customAnnotationView)
         {
             customAnnotationView = [[CustomAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
             UITapGestureRecognizer *tapGesture =
             [[UITapGestureRecognizer alloc] initWithTarget:self
                                                     action:@selector(calloutTapped:)];
             [customAnnotationView addGestureRecognizer:tapGesture];
然后

    -(void) calloutTapped:(id) sender {
       id<MKAnnotation> annotation = ((MKAnnotationView*)sender.view).annotation;

我在哪里坏了?

请尝试此操作。并确保将MKMapViewDelegate设置为该类

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
    {
        if([view isKindOfClass:[myCustomAnnotaionClass class]])
        {
            //your programming logic here
        }
    }

“这不起作用”-您忘了将mapView委托设置到实现此方法的对象吗?是的,map不会对此作出反应。您还必须将详图索引有效地添加到注释中-默认情况下它不会显示。在MKAnnotationView中尝试将“canShowCallout”设置为“是”。默认情况下,它将显示一个(i)图标,但您也可以自定义它。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
    {
        if([view isKindOfClass:[myCustomAnnotaionClass class]])
        {
            //your programming logic here
        }
    }