函数pinpressed方法calloutAccessoryControlTapped不起作用….
这是一个示例代码:
import UIKitimport MapKitimport CoreLocationclass VIEwController: UIVIEwController,MKMapVIEwDelegate,CLLocationManagerDelegate {@IBOutlet weak var mainMapVIEw: MKMapVIEw!var locationManager = CLLocationManager()overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestAlwaysAuthorization() locationManager.startUpdatingLocation() var objectLatitude = 53.204526 var objectLongitude = 50.111751 var currentLatitude = 53.203715 var currentLongitude = 50.160374 var latDelta = 0.05 var longDelta = 0.05 var currentLocationSpan: MKCoordinateSpan = MKCoordinateSpanMake(latDelta,longDelta) var currentLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude) var currentRegion: MKCoordinateRegion = MKCoordinateRegionMake(currentLocation,currentLocationSpan) self.mainMapVIEw.setRegion(currentRegion,animated: true) var objectLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(objectLatitude,objectLongitude) var objectAnnotation = MKPointAnnotation() objectAnnotation.coordinate = objectLocation objectAnnotation.Title = "St. George's Church" objectAnnotation.subTitle = "Church of the Great Martyr St. George" self.mainMapVIEw.addAnnotation(objectAnnotation)}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!.pincolor = .Purple pinVIEw!.rightCalloutAccessoryVIEw = UIbutton.buttonWithType(.Detaildisclosure) as UIbutton } else { pinVIEw!.annotation = annotation } return pinVIEw}func pinpressed(mapVIEw: MKMapVIEw!,annotationVIEw: MKAnnotationVIEw,calloutAccessoryControlTapped control: UIControl) { if control == annotationVIEw.rightCalloutAccessoryVIEw { println("disclosure pressed!") }}overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning()}}解决方法 calloutAccessoryControlTapped委托方法必须命名为mapVIEw(annotationVIEw:calloutAccessoryControlTapped :).
您不能使用自己的名称,如pinpressed(…).
这适用于任何委托方法,并由协议规定.
所以它应该是:
func mapVIEw(mapVIEw: MKMapVIEw!,calloutAccessoryControlTapped control: UIControl) { if control == annotationVIEw.rightCalloutAccessoryVIEw { println("disclosure pressed!") }}总结
以上是内存溢出为你收集整理的Swift中的MapKit,第2部分全部内容,希望文章能够帮你解决Swift中的MapKit,第2部分所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)