- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    NSLog(@"I'm Working");
    static NSString *identifier = @"MyLocation";
    if ([annotation isKindOfClass:[userPins class]]) {
      userPins *location = (userPins *) annotation;

      MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
      if (annotationView == nil) {
          annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
      } else {
          annotationView.annotation = annotation;
      }

      annotationView.enabled = YES;
      annotationView.canShowCallout = YES;

      if ([location.name compare:@"LARCENY"] == NSOrderedSame) {
          annotationView.pinColor = MKPinAnnotationColorGreen;
      }
      return annotationView;
    }

    return nil;
}


此代码不起作用。我正在从JSON添加图钉。我看到红色的针脚,但看不到nslog(我在工作)。有任何想法吗?

最佳答案

您需要在viewDidLoad或笔尖或创建它的任何位置设置mapView的委托。

关于objective-c - MKAnnotationView没什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7597829/

10-11 14:50