首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >viewForAnnotation返回nil

viewForAnnotation返回nil
EN

Stack Overflow用户
提问于 2016-09-04 18:54:57
回答 1查看 632关注 0票数 1

我正在尝试制作一个自定义的注解。我创建了一个定制的注解类,在其中我设计了注解视图。我正在尝试调用我的视图控制器中的viewForAnnotation中的类。当我运行应用程序时,它会向我显示基本视图。下面是函数。如果您也想查看自定义注释类,请让我知道。

代码语言:javascript
运行
复制
 func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {


    let reuseIdentifier = "CustomAnnotation"


    if (annotation.isKindOfClass(CustomAnnotation)) {
        var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseIdentifier) as! CustomAnnotation!


        annotationView = CustomAnnotation(annotation: annotation, reuseIdentifier: reuseIdentifier)

        return annotationView
    }
        else {
            return nil
    }

}
EN

回答 1

Stack Overflow用户

发布于 2016-09-05 14:21:18

函数注释(mapView: MKMapView,viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?{ if annotation is MKUserLocation { return nil }

代码语言:javascript
运行
复制
    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView?.animatesDrop = true
        pinView?.canShowCallout = false
        pinView?.draggable = true
              }
    else {
    }

    return pinView
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39316153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档