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
}
}