在注释视图中使用canShowCallout时MKMapKit异常 [英] MKMapKit exception when using canShowCallout on annotation view

查看:113
本文介绍了在注释视图中使用canShowCallout时MKMapKit异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用pretty简单的自定义地图标注视图和标​​注 - 当我创建它的标注来看,只是增加了一个UIImageView作为子视图本身。这工作正常。

I'm trying to use a pretty straightforward custom map annotation view and callout - the annotation view when I create it, just adds a UIImageView as a subview to itself. That works fine.

然而,当我打电话canShowCallout的标注来看,一个例外是返回的观点后,立即扔在MapKit。堆栈的结尾是这样的:

However, when I call canShowCallout on the annotation view, An exception is thrown in MapKit immediately after returning the view. The end of the stack looks like:

#0  0x94e964e6 in objc_exception_throw
#1  0x01e26404 in -[MKOverlayView _addViewForAnnotation:]
#2  0x01e22037 in -[MKOverlayView _addViewsForAnnotations:animated:]
#3  0x01e1ddf9 in -[MKOverlayView showAddedAnnotationsAnimated:]
#4  0x01df9c0e in -[MKMapView _showAddedAnnotationsAndRouteAnimated:]
#5  0x01e0371a in -[MKMapView levelView:didLoadTile:]

我viewForAnnotation是pretty简单:

My viewForAnnotation is pretty simple:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ( ! [annotation isKindOfClass:[MyAnnotation class]] )
        return nil;

    MyAnnotationView *useView = (MyAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:@"resuseview"];
    if ( useView == nil )
    {
        useView = [[[MyAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"resuseview"] autorelease];
        useView.canShowCallout = YES;  // if commented out view appears just fine
    }
    else
    {   useView.annotation = annotation;  }

    return useView;
}

由于在code所指出的,标注视图工作正常的是 - 直到我加入canShowCallout,那么它崩溃首次地图获取视图

As noted in the code, the annotation view works fine as is - until I add canShowCallout, then it crashes the first time the map gets the view.

推荐答案

的答案竟然是MyAnnotation(其中实现MKAnnotation协议)没有实现两个可选的协议方法:

The answer turned out to be that MyAnnotation (which implements the MKAnnotation protocol) did not implement the two optional protocol methods:

- (NSString *)subtitle;
- (NSString *)title;

由于我曾在一个完全定制的标注计划,我不认为我需要来定义这些 - 和调用堆栈并没有显示无法识别的选择

Because I had planned on a totally custom callout, I did not think I needed to define these - and the call stack did not show unrecognized selectors.

此外,我实现了这两个刚刚返回nil,却发现为了注释实际激活标注的标题方法(至少)必须返回一个非零值,否则标注不会是presented。

Additionally, I implemented these two just to return nil, but found that in order for an annotation to actually activate a callout the title method (at least) MUST return a non-nil value, or else the callout will not be presented.

这篇关于在注释视图中使用canShowCallout时MKMapKit异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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