无法选择一个注解? [英] Can't select an annotation?

查看:161
本文介绍了无法选择一个注解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个地图视图中的单个注释。我可以programmaticly选择它,但我点击它没有任何反应。你可以帮帮我吗?有没有人遇到类似的问题?下面是mehod设立anotations:

I have a single annotation on a map view. I can select it programmaticly, but the I tap it nothing happens. Could you help me? Did anyone encounter similar problem? Here is mehod for setting up anotations:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
    if (!aView) {
        aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
        aView.canShowCallout = YES;
        aView.draggable=YES;
        aView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        // could put a rightCalloutAccessoryView here
    }
    aView.annotation = annotation;
    [(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
    return aView;
}

和将它们添加到地图视图:

And adding them to map view:

- (void)updateMapView
{
    if (self.mapView.annotations) [self.mapView removeAnnotations:self.mapView.annotations];
    if (self.annotation) [self.mapView addAnnotation:self.annotation];
}

和mehod反应注释pressing:

And mehod reacting to pressing of annotations:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView
{
    NSLog(@"did select annotation");
}

顺便说一句,方法[self.mapView selectAnnotation:注释]的作品,但不把一个标注(我断点检查它)。虽然只是盘带批注不(再通过断点cheked)。

By the way, method [self.mapView selectAnnotation:annotation] works, but doesn't put up a callout(i checked it with breakpoint). While just taping annotation doesn't(again cheked through breakpoints).

推荐答案

如果一个注解的标题是零或空白,标注将不会显示(即使其他一切正确设置包括 canShowCallout )。

If an annotation's title is nil or blank, the callout will not show (even if everything else is set properly including canShowCallout).

当您在注释挖掘,在 didSelectAnnotationView 委托方法将被调用,如果标注有一个非空标题,标注将被显示。

When you tap on an annotation, the didSelectAnnotationView delegate method will get called and if the annotation has a non-blank title, the callout will be displayed.

结果
至于在评论你的问题:


Regarding your question in the comments:

...是不是我有一个单独的类来包装在我所有的数据,我
  注释类包含的数据类的实例?

...is it right I have a seperate class to wrap all my data in to, my annotation class contains an instance of that data class?

有什么错。结果
如果你想保持与地图相关的逻辑分离从基类,这很好,也许对于一个复杂的应用程序,其中基础数据类可用于不仅仅是注释更是一个好主意。

There's nothing wrong with this.
If you want to keep map-related logic separate from the base class, that's fine and probably a good idea for a complex app where the base data class may be used for more than just annotations.

如果您的应用程序是非常简单的数据仅用于注解,你可以让事情变得非常简单,将二者结合起来,但它不是必需的。

If your app is very simple and the data is only used for annotations, you could keep things very simple and combine the two but it's not a requirement.

只要你坚持使用直接引用,而不是试图,例如,使用数组索引或查看/按钮标签从注释链接回一些数据对象,正确的类实现取决于什么工作您的应用程序。

As long as you stick to using direct references instead of trying to, for example, use array indexes or view/button tags to link back to some data object from the annotation, the "right" class implementation depends on what works for your app.

这篇关于无法选择一个注解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆