まとめ: アプリからの解析による (クエリではない) アノテーションのリンク
完了: 私がやろうとしているのは、新しく作成された注釈を結果として PFObject にすることです。私がこれをしようとしている方法は、MKPointAnnotation に基づいて座標を取得することです。次に、それを座標付きの PFObject に変換します。その後、ライブ更新として後でクエリを実行できます。
問題 まだ問題は、言及されたコードでは、タイトルと UIImage を追加できるようにする MKPointAnnotation を持つことができないということです。パースからクエリされます。
func handleLongPress(getstureRecognizer : UIGestureRecognizer) {
if getstureRecognizer.state != .Began { return }
let touchPoint = getstureRecognizer.locationInView(self.mapView)
let touchMapCoordinate = mapView.convertPoint(touchPoint, toCoordinateFromView: mapView)
createAnnotation(touchMapCoordinate)
}
private func createAnnotation(coordinate: CLLocationCoordinate2D) {
print("createAnnotation")
let myAnnotation = MyAnnotation(coordinate: coordinate)
mapView.addAnnotation(myAnnotation)
myAnnotation.saveInBackground()
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if !(annotation is MKPointAnnotation) {
return nil
}
let reuseId = "test"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if pinView == nil {
pinView = MyAnnotation(annotation: annotation, reuseIdentifier: reuseId)
pinView!.image = UIImage(named:"Cloud9")
pinView!.canShowCallout = true
let rightButton: AnyObject! = UIButton(type: UIButtonType.ContactAdd)
pinView?.rightCalloutAccessoryView = rightButton as? UIView