Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 对'的重新声明无效;mapView(ux0:viewFor:)&x27;_Ios_Swift_Xcode - Fatal编程技术网

Ios 对'的重新声明无效;mapView(ux0:viewFor:)&x27;

Ios 对'的重新声明无效;mapView(ux0:viewFor:)&x27;,ios,swift,xcode,Ios,Swift,Xcode,因此,我正在尝试创建一个在地图上带有自定义注释的应用程序,并且我一直在遵循一个关于如何做到这一点的教程。然而,当我把这个代码放进去时,它给了我一个错误 “mapView(\u0:viewFor:)”的重新声明无效 以下是教程- 当您已经在其他地方实现了该方法时,通常会发生这种情况 检查ViewController以确保没有func映射视图(\mapView:MKMapView,viewforannotation:MKAnnotation)->MKAnnotationView?{}在该扩展之外实现

因此,我正在尝试创建一个在地图上带有自定义注释的应用程序,并且我一直在遵循一个关于如何做到这一点的教程。然而,当我把这个代码放进去时,它给了我一个错误

“mapView(\u0:viewFor:)”的重新声明无效

以下是教程-


当您已经在其他地方实现了该方法时,通常会发生这种情况


检查ViewController以确保没有
func映射视图(\mapView:MKMapView,viewforannotation:MKAnnotation)->MKAnnotationView?{}
在该扩展之外实现。

当您已经在其他地方实现了该方法时,通常会发生这种情况

检查ViewController以确保没有
func映射视图(\mapView:MKMapView,viewforannotation:MKAnnotation)->MKAnnotationView?{}
在该扩展之外实现

extension ViewController: MKMapViewDelegate {
    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        guard let _annotation = annotation as? MyAnnotation else {return }
        let identifier = "marker"
        var view: MKMarkerAnnotationView
        if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView {
            dequeuedView.annotation = annotation
            view = dequeuedView
        }
        else
        {
           view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            view.canShowCallout = true
            view.calloutOffset = CGPoint(x: -5, y: 5)
            view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
        }
        return view
    }
}