地图视图的selectAnnotation方法在iOS7上无法工作

3

我正在处理一个iPhone应用程序,在其中需要展示不同位置的兴趣点标记。我需要在第一个兴趣点上默认弹出提示框。我已经成功实现了iOS6的相关功能,但在iOS7中遇到了问题。以下是我的代码部分,它在iOS6中运行良好,但在iOS7中无法默认弹出提示框,没有显示任何错误。

以下是我的代码:

DDAnnotation *annotation2 = [[DDAnnotation alloc] initWithCoordinate:coordinates addressDictionary:nil] ;
        annotation2.title = [[arrPOIs objectAtIndex:0] objectForKey:@"Name"];
        annotation2.subtitle = [[arrPOIs objectAtIndex:0] objectForKey:@"AmbassadorTagline"];
        annotation2.dictionaryData = [arrPOIs objectAtIndex:0];
        annotation2.strCountNumber = [NSString stringWithFormat:@"1"];

[mapView selectAnnotation:annotation2 animated:YES];
        [annotation2 release];
        annotation2 = nil;

如果您对此有任何想法/建议,请指导我。


“DDAnnotation” 是来自 https://github.com/digdog/MapKitDragAndDrop 的吗?这个项目已经好几年没有更新了,也许不兼容 iOS 7。 - oefe
请展示您在mapView上如何/何处添加注释的正确代码。 - AJPatel
3个回答

2
我用这个代码在iOS7上运行很好。
首先,
#import <MapKit/MapKit.h>

那么在

ViewDidLoad

方法中添加如下代码:

CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = someLocation;
annotationCoord.longitude = someLocation;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = @"YourTitle";
annotationPoint.subtitle = @"YourSubtitle";
[map addAnnotation:annotationPoint];

谢谢Abdullah,我找到了解决方案。在选择注释之前,我错过了添加一行代码。即: [mapView addAnnotation:annotationPoint];令人惊讶的是,它对iOS6没有影响。这个问题只出现在iOS7上。 - user2897266

1

我已经测试了这种方法,对于DDAnnotaion和简单的地图视图放置标注都适用于iOS 7。可能存在以下情况:

1) Annotation is not visible on mapView.
2) Annotation is not yet created/added to mapView.

所以请检查一下。或者提供您添加注释的完整代码及其位置。

请查看此处的讨论点,以获取更多想法。


感谢AJPatel的回答。在我的情况下,影响的是no-"2"。我忘记在选择之前添加它了。 - user2897266
是的,我知道。你有检查过你的整个代码吗?为什么它只在iOS 6上运行? - AJPatel

1
感谢大家。最终,我找到了我的问题的解决方案。
在选择注释之前,我忘记添加一行。那是: [mapView addAnnotation:annotationPoint];
令人惊讶的是,这对iOS6没有影响。这个问题只出现在iOS7中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接