2015-07-20 49 views
0

我已添加以下代碼,並且無法看到任何引腳更改與新圖像,並且沒有錯誤顯示。 map.delegate =自己完成。我們是否需要添加任何代碼來使其工作?任何幫助?使用Xcode 7更改MKMapView上的引腳圖像Swift2

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    let userLocation:CLLocation = locations[0] as CLLocation 
    let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta) 
    let region:MKCoordinateRegion = MKCoordinateRegionMake(userLocation.coordinate, span) 


    routeMapView.setRegion(region, animated: true) 

    currentLocationAnnotation.coordinate = userLocation.coordinate 
    mapView(routeMapView, viewForAnnotation: currentLocationAnnotation)!.annotation = currentLocationAnnotation 
    routeMapView.addAnnotation(currentLocationAnnotation) 
    //print("getting current location..") 
    getCurrentLocationAddress(userLocation) 

    userCurrentLocation = userLocation 
    userLocationSpan = span 
    counter++ 

} 


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

     if annotation is MKUserLocation { 
      //return nil so map view draws "blue dot" for standard user location 
      return nil 
     } 

     let reuseId = "pin" 
     var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView 
     if pinView == nil { 
      pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
      pinView!.canShowCallout = true 
      pinView!.animatesDrop = true 
      pinView!.image = UIImage(named:"first")! 
      print(pinView!.image!) 
      routeMapView.delegate = self 
     } 
     else { 
      pinView!.annotation = annotation 
     } 

     return pinView 
} 

回答

1

我不確定您是否已經在viewDidLoad方法中爲您的mapView設置了委託。如果不是,請做。因爲在viewForAnnotation中設置它永遠不會調用這個委託方法。將routeMapView.delegate = self從viewForAnnotation移動到viewDidLoad方法。

+0

感謝它的工作。 – sfbayman