npmrtsv
npmrtsv

Reputation: 434

didSelectAnnotationView doesn't call on custom MKAnnotationView

  1. I have set delegate on mapView
  2. I've set setCanShowCallout: to YES
  3. Code from my custom MKAnnotationView:

    - (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
     self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
        if (self) {
        self.canShowCallout = YES;
        _pinView = [[CustomPinView alloc] init];
        [self addSubview:_pinView];
     }
    return self;
    }
    
  4. Code from my VC:

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
      MapAnnotationView *pinView = nil;
    
      pinView = (MapAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"lol"];
      if (pinView == nil){
          pinView = [[MapAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"lol"];
      }
      return pinView;
    }
    

What am I doing wrong, pls help me.

Upvotes: 0

Views: 830

Answers (1)

npmrtsv
npmrtsv

Reputation: 434

Allright, I'll do it by myself.

  1. You should set image to your custom MKAnnotationView with size of subviews.

  2. You should set canShowCallout = YES only if your MKPointAnnotation has description string (not nil, or @""), otherwise you should set canShowCallout = NO

After that method didSelectAnnotationView will be called. Hope it helps for someone.

Upvotes: 2

Related Questions