1

我正在为 ios 9 开发一个应用程序。因为我更新到 7.1 版本我有这个错误:命令失败由于信号:分段错误:11

查看代码,我发现这段代码导致了这个错误:

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
    if !(annotation is ADBaseAnnotation){
        print("No es ADBaseAnnotation",terminator:"\n")
        return nil
    }

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier((annotation as! ADBaseAnnotation).getReuseId())
    if let normal = annotation as? NormalParking {
        //anView = normal.getAnnotationView(annotation, reuseIdentifier: normal.getReuseId())
    } else if let hightlight = annotation as? HightLightParking{
        //anView = hightlight.getAnnotationView(annotation, reuseIdentifier: hightlight.getReuseId())
    }
    return anView
}

该错误是由注释行引起的。请帮忙

4

1 回答 1

1

这是编译器确实失败的问题,还是在正常编译后仍会突出显示发生错误的代码行?当编译器对我编写的代码感到困惑并且无法编译并且在内部发生某种崩溃时,我经常会遇到这种情况。如果是这种情况,您可以在编译日志中找到更详细的信息。通常这是我自己的错,但编译器仍然太新,无法提供良好的反馈或以优雅的方式处理这种情况。

我不知道确切的问题,但我注意到有关您的代码的一些事情。对我来说看起来很有趣的是:

if let normal = annotation as? NormalParking {
        anView = normal.getAnnotationView(annotation, reuseIdentifier: normal.getReuseId())
    }

为什么不使用相同的转换变量,例如:

if let normal = annotation as? NormalParking {
        anView = normal.getAnnotationView(normal, reuseIdentifier: normal.getReuseId())
    }

而且你在施法后做的完全一样,实际上你根本不需要施法。

例如:

guard let annotation = annotation as? ADBaseAnnotation else {
    print("No es ADBaseAnnotation",terminator:"\n")
    return nil
}

if annotation is NormalParking || annotation is HightLightParking {
    return annotation.getAnnotationView(annotation, reuseIdentifier: annotation.getReuseId())
}

return mapView.dequeueReusableAnnotationViewWithIdentifier(annotation).getReuseId())

我假设 ADBaseAnnotation 是定义 getReuseId() 的共享基类,并且您的停车实现覆盖 getReuseId()

于 2015-10-26T01:15:37.433 回答