請大家幫忙。 =)我有一個問題來設置標註標題。我通過謂詞接收來自核心數據的信息。 當我點擊地圖上的註釋時,我收到了我日誌中的所有數據。在Swift 2.0中設置callout註釋標題爲「DidSelectAnnotationView」,DataData爲CoreData
如何在標註泡泡中設置標題?所有的
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView:MKPinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "CheckpointPins")
if annotation is MKUserLocation {
return nil }
else {
let pred:NSPredicate = NSPredicate(format: "checkpoint_longitude != nil && checkpoint_latitude != nil")
let items = fetchedResultsController?.fetchedObjects
let filt = (items! as NSArray).filteredArrayUsingPredicate(pred)
let startCheckPoint:Checkpoint = (filt as NSArray).firstObject as! Checkpoint!
let endCheckpoint:Checkpoint = (filt as NSArray).lastObject as! Checkpoint!
if filt.count != 0 {
if startCheckPoint .isEqual(annotation) {
annotationView.pinTintColor = MKPinAnnotationView.greenPinColor()
}else if endCheckpoint.isEqual(annotation) {
annotationView.pinTintColor = MKPinAnnotationView.purplePinColor()
}else {
annotationView.pinTintColor = MKPinAnnotationView.redPinColor()
}
}
let point = annotation as! Checkpoint
annotationView.tag = (point.checkpoint_order?.integerValue)!
annotationView.enabled = true
annotationView.animatesDrop = true
// annotationView.canShowCallout = true
annotationView.annotation = annotation
// annotationView.opaque = false
print("tag = \(annotationView.tag)")
}
return annotationView
}
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
if !(view.annotation!.isKindOfClass(MKUserLocation)) {
let pred:NSPredicate = NSPredicate(format: "checkpoint_longitude != nil && checkpoint_latitude != nil")
let pred2:NSPredicate = NSPredicate(format: "checkpoint_order == %d", view.tag)
let compoundPredicate:NSPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [pred, pred2])
let items = fetchedResultsController?.fetchedObjects
let filt = (items! as NSArray).filteredArrayUsingPredicate(compoundPredicate)
let point:Checkpoint = (filt as NSArray).firstObject as! Checkpoint
print(point.description)
}
}
}
爲什麼'annotationView.canShowCallout = true'被註釋掉了? –
當我將它設置爲true時,它墜毀了。請參閱日誌:必須在相應視圖上的canShowCallout爲YES時實現標題>可見:1 +48.40999985,+16.19169998' –
Koppi