MapView崩溃,设置为委托

时间:2015-12-10 22:04:51

标签: swift mapkit geocode

我正在将我的地图视图设置为委托,所以我可以在我的引脚上放置注释标注,但是我有一个地理编码,只有在单击按钮时才会执行其他操作。当我将地图视图设置为委托时,我尝试放置一个引脚崩溃。我该如何解决这个问题?

func action(gestureRecognizer:UIGestureRecognizer) {
    let touchPoint = gestureRecognizer.locationInView(self.mapView)
    let newCoord:CLLocationCoordinate2D = mapView.convertPoint(touchPoint, toCoordinateFromView: self.mapView)

    //var newAnotation = MKPointAnnotation()

    //
    self.mapView.delegate = self
    //

    self.newAnotation = MKPointAnnotation()
    self.newAnotation.coordinate = newCoord
    newAnotation.title = "New Location"
    newAnotation.subtitle = "New Subtitle"
    //mapView.addAnnotation(newAnotation)

    self.pinAnnotationView = MKPinAnnotationView(annotation: self.newAnotation, reuseIdentifier: nil)

    self.mapView.centerCoordinate = self.newAnotation.coordinate
    self.mapView.addAnnotation(self.pinAnnotationView.annotation!)
}

崩溃的屏幕截图,

enter image description here

1 个答案:

答案 0 :(得分:0)

您必须在控制台输出中收到以下错误日志。这就是因为您尚未初始化var idSortByRank = ["cxwMoC3k6kpf4mr5o", "HFYjC5nuT9hKhdyFC", "GiM7NCLjck6Pet8Wm"], data = [{ "_id": "GiM7NCLjck6Pet8Wm" }, { "_id": "HFYjC5nuT9hKhdyFC" }, { "_id": "cxwMoC3k6kpf4mr5o" }]; data.sort(function (a, b) { return idSortByRank.indexOf(a._id) - idSortByRank.indexOf(b._id); }); document.write('<pre>' + JSON.stringify(data, 0, 4) + '</pre>');实例。

geoCoder

声明它就像这样

fatal error: unexpectedly found nil while unwrapping an Optional value
相关问题