【问题标题】:iOS6 not showing MKAnnotationView calloutiOS6 不显示 MKAnnotationView 标注
【发布时间】:2012-10-10 15:30:27
【问题描述】:

我一直在寻找这个问题的根源,但我看不出哪里出了问题。我希望你能在这里帮助我。

我正在尝试在 mapView 中显示注释,图钉被丢弃但无法看到标注,直到我先点击用户位置注释(蓝点),然后返回并点击注释,然后点击注释显示,一切正常。另一种方法是在引脚周围随机敲击,有时在内部敲击,运气好的话,它会显示标注。如果我在地图上放置另一个图钉,我必须执行相同的程序。

这只发生在 iOS6、模拟器和设备中。 iOS5 完美运行。

这是我用于 viewForAnnotation 的代码

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    MKAnnotationView *annotationView = nil;

    //Check if this annotation is not the blue dot for user location
    if(annotation != mapView.userLocation) {

        //Try to rehuse a previous annotation
        annotationView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:@"searchResult"];

        //If we don't have any, create it
        if (annotationView == nil) {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"searchResult"];
        }
        else {//Or re use it
            annotationView.annotation = annotation;
        }


        [annotationView setImage: [UIImage imageNamed:@"customMarker.png"]];
        annotationView.enabled = YES;
        annotationView.canShowCallout = YES;
        annotationView.centerOffset = CGPointMake(0,-16);
        annotationView.rightCalloutAccessoryView = nil;//Avoid again the detail button because is a geographic reference


    }
    else {//Show a text when the blue dot for user location is pressed
        [mapView.userLocation setTitle:NSLocalizedString(@"you_are_here", nil)];
    }

    return annotationView;

}

【问题讨论】:

  • 你应该把这个注解去掉View.centerOffset = CGPointMake(0,-16);
  • 我之前试过,结果一样。
  • 注解的标题是怎么设置的?在 didSelectAnnotationView 中做了什么吗?地图上是否使用了任何手势识别器?
  • @AnnaKarenina 我刚刚删除了手势的所有代码,在 didSelectAnnotationView 我有这个:但仍然没有做任何事情。- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { if([self.map.annotations objectAtIndex:0] != map.userLocation){ id&lt;MKAnnotation&gt; myAnnotation = [self.map.annotations objectAtIndex:0]; [self.map selectAnnotation:myAnnotation animated:YES]; } }
  • 无法使用显示的代码进行复制。注解的标题是怎么设置的?

标签: iphone ios ios6 mkannotationview ios6-maps


【解决方案1】:

我发现了问题。

我创建自定义 MKAnnotation 的方式如下:

使用这个自定义类:http://gist.github.com/3866874 然后这段代码:

MapAnnotation *location = [[MapAnnotation alloc] init];
location.title = @"some title";
location.subtitle =@"some subtitle";
location.coordinate = mapRegion.center;
location.placeData = resultSet;
[map setDelegate:self];
[map addAnnotation:location];
[map selectAnnotation:location animated:YES]; //THIS LINE WAS CAUSING THE PROBLEM IN IOS6

我刚刚删除了这条线

[map selectAnnotation:location animated:YES];

现在标注显示正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    • 2011-12-22
    相关资源
    最近更新 更多