MKAnnotationView 不做任何事情
- (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(我正在工作)。有什么想法吗?
- (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;
}
This code not working. I'm adding pins from JSON. I see red pins but I can't see nslog(I'm working). Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 viewDidLoad 或 nib 中或您创建它的任何位置设置 mapView 的委托。
You need to set the mapView's delegate in viewDidLoad or in the nib or wherever you are creating it.