iphone - iOS6 不显示 MKAnnotationView 标注

标签 iphone ios ios6 mkannotationview ios6-maps

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

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

这只发生在 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;

}

最佳答案

我发现了问题。

我创建自定义 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];

现在标注显示正确。

关于iphone - iOS6 不显示 MKAnnotationView 标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12823046/

相关文章:

ios - 如何使用xib实现UILabel的行间距?

iphone - MPMoviePlayerController 在 iOS 5 xcode(带有 Storyboard )中不起作用,但在 iOS 4 中完美运行

ios - Swift 中的 NSTextStorage 子类不更新 UITextView

iOS GCD 线程处理 - View Controller 已关闭

iphone - NSContactsUsageDescription 不起作用

ios6 - dyld:找不到符号:__ZTISt9exception

iphone - 如何在UIactivityviewcontroller中添加Facebook、twitter、邮件、消息图标

ios - 在 NSUserDefaults 中存储图像以在 tableView 中显示它们时出现问题。 swift

iphone - 由于某些字符,NSData 到 NSString 的转换失败

ios - 返回按初始位置排序的字典中的所有值