MapKit 中没有显示标签

No Labels being displayed in MapKit

谁能告诉我为什么我的标签没有显示。我是 运行 一个循环,其中包含一个包含坐标的数组。它显示我的 3 个引脚,其中 1 个是绿色,两个是蓝色,这是我想要的,但我的标签没有显示,有什么想法吗?

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

    @IBOutlet weak var maps: MKMapView!
    var locationManager = CLLocationManager()
    var flag = true

    override func viewDidLoad() {
        super.viewDidLoad()
        let CoordinatesArray = ["blah,-blah, 11:45","blah, -blah,00:00", "blah,-blah, 12:45"];
        self.maps.delegate = self
        sendPoints(CoordinatesArray);

    }

    func sendPoints(array:[String]){
        let latDelta:CLLocationDegrees = 0.015 //difference of lats from one side of screen to another
        let longDelta:CLLocationDegrees = 0.015 //difference of lats from one side of screen to another
        let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)

        for (var i=0;i<array.count;i++){

            var separateComma = array[i].componentsSeparatedByString(",")
            var location:CLLocationCoordinate2D

            if(flag){
                location = CLLocationCoordinate2DMake(separateComma[0].doubleValue,separateComma[1].doubleValue)
                let length:CLLocationDistance = 200
                let cir:MKCircle = MKCircle(centerCoordinate: location, radius: length)
                maps.addOverlay(cir)


            }else{
                location = CLLocationCoordinate2DMake(separateComma[0].doubleValue,separateComma[1].doubleValue)

            }

            let point = MKPointAnnotation()
            point.title = "Home"
            point.subtitle = "time for home"
            point.coordinate = location
            maps.addAnnotation(point)
            maps.selectAnnotation(point, animated: true)
            maps.setRegion(MKCoordinateRegionMake(point.coordinate, MKCoordinateSpanMake(latDelta,longDelta)), animated: true)

        }
    }


    func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
        let overlayRenderer : MKCircleRenderer = MKCircleRenderer(overlay: overlay);
        overlayRenderer.lineWidth = 150
        overlayRenderer.fillColor = UIColor.blueColor()

        overlayRenderer.alpha = 0.15

        return overlayRenderer
    }

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

        if (annotation.isKindOfClass(MKUserLocation)){
            return nil
        }
        var myPin = mapView.dequeueReusableAnnotationViewWithIdentifier("MyIdentifier") as? MKPinAnnotationView
        if myPin != nil {
            return myPin
        }

        myPin = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "MyIdentifier")
        if(flag){
            myPin?.pinTintColor = UIColor.greenColor()
        }else{
            myPin?.pinTintColor = UIColor.blueColor()
        }
        flag = false;
        return myPin
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

extension String {
    var doubleValue: Double {
        return (self as NSString).doubleValue
    }
}

你必须设置 canShowCallout 属性.

    myPin = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "MyIdentifier")
    myPin?.canShowCallout = true

在我的例子中,我在被调用之前委托了地图。

所以...这就是我面临的错误。

self.m_map = MKMapView()
self.m_map?.delegate = self

希望对大家有所帮助:-)