Swift - Ambiguos对成员'mapView(_ :: viewForAnnotation :)

时间:2016-08-31 10:21:40

标签: swift xcode

我是swift的新手,我正试图找出我的代码有什么问题。我正在尝试使用mapKit为地图创建自定义注释。我正在使用引用,但我仍然得到4个相同的错误。 `错误似乎与自我有关。功能。任何帮助将不胜感激!1错误显示为asterix

    // 1
    coordinates = [[48.85672,2.35501],[48.85196,2.33944],[48.85376,2.33953]]// Latitude,Longitude
    names = ["Coffee Shop · Rue de Rivoli","Cafe · Boulevard Saint-Germain","Coffee Shop · Rue Saint-André des Arts"]
    addresses = ["46 Rue de Rivoli, 75004 Paris, France","91 Boulevard Saint-Germain, 75006 Paris, France","62 Rue Saint-André des Arts, 75006 Paris, France"]
    phones = ["+33 1 44 78 94 78","+33 1 46 34 52 68","+33 1 46 34 06 72"]
    **self.mapView.delegate = self**
    // 2
    for i in 0...2
    {
        let coordinate = coordinates[i]
        let point = StarbucksAnnotation(coordinate: CLLocationCoordinate2D(latitude: coordinate[0] as! Double, longitude: coordinate[1] as! Double))
        point.image = UIImage(named: "starbucks-\(i+1).jpg")
        point.name = names[i]
        point.address = addresses[i]
        point.phone = phones[i]
        **self.mapView.addAnnotation(point)**
    }
    // 3
    let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 48.856614, longitude: 2.3522219000000177), span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1))
    **self.mapView.setRegion(region, animated: true)**
}

//MARK: MKMapViewDelegate
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    if annotation is MKUserLocation
    {
        return nil
    }
    **var annotationView = self.mapView.dequeueReusableAnnotationViewWithIdentifier("Pin")**
    if annotationView == nil{
        annotationView = AnnotationView(annotation: annotation, reuseIdentifier: "Pin")
        annotationView?.canShowCallout = false
    }else{
        annotationView?.annotation = annotation
    }
    annotationView?.image = UIImage(named: "starbucks")
    return annotationView
}
func mapView(mapView: MKMapView,
             didSelectAnnotationView view: MKAnnotationView)
{
    // 1
    if view.annotation is MKUserLocation
    {
        // Don't proceed with custom callout
        return
    }
    // 2
    let starbucksAnnotation = view.annotation as! StarbucksAnnotation
    let views = NSBundle.mainBundle().loadNibNamed("CustomCalloutView", owner: nil, options: nil)
    let calloutView = views[0] as! CustomCalloutView
    calloutView.starbucksName.text = starbucksAnnotation.name
    calloutView.starbucksAddress.text = starbucksAnnotation.address
    calloutView.starbucksPhone.text = starbucksAnnotation.phone
    let tapGesture = UITapGestureRecognizer(target: self, action: "CallPhoneNumber:")
    calloutView.starbucksPhone.addGestureRecognizer(tapGesture)
    calloutView.starbucksPhone.userInteractionEnabled = true
    calloutView.starbucksImage.image = starbucksAnnotation.image
    // 3
    calloutView.center = CGPointMake(view.bounds.size.width / 2, -calloutView.bounds.size.height*0.52)
    view.addSubview(calloutView)
}
func mapView(mapView: MKMapView, didDeselectAnnotationView view: MKAnnotationView) {
    if view.isKindOfClass(AnnotationView)
    {
        for subview in view.subviews
        {
            subview.removeFromSuperview()
        }
    }
}

`

0 个答案:

没有答案