2016-08-04 5 views
0

私は、スピーディーでオブジェクト指向のプログラミングには新しく、マップを含むビューから別のビューにビューを切り替えようとしています。長い押しで落とされたピンの注釈の右のアクセサリコールアウトボタン。ストーリーボードでは、私は2つのビューの間にセグを作成し、識別子mapsegでセグを割り当てました。残念ながら、私はGoogle経由で見つけることができたすべてを試した後、右のアクセサリーの吹き出しボタンをタップして理由がわからないときにセグを得ることができません。アプリケーション自体はタブ付きのタブ付きアプリケーションです。 2番目のタブのビューはマップを含むビューです。また、これが何かと関係するかどうかはわかりませんが、移行しようとしているビューはナビゲーションコントローラに組み込まれています。ここから移行しようとしているビューのコードです。地図の注釈で右のアクセサリのコールアウトボタンをタップしてビューを分割する方法をスピーディーにする

import UIKit 
import MapKit 

class SecondViewController: UIViewController, MKMapViewDelegate { 

    @IBOutlet weak var MapView: MKMapView! 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.MapView.delegate = self 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

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

    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
     let reuseID = "pin" 
     var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseID) as? MKPinAnnotationView 
     pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID) 
     pinView!.canShowCallout = true 
     pinView!.animatesDrop = true 
     pinView!.enabled=true 
     let btn = UIButton(type: .DetailDisclosure) 
     btn.titleForState(UIControlState.Normal) 
     pinView!.rightCalloutAccessoryView = btn as UIView 
     return pinView 
    } 


    @IBAction func dropPin(sender: UILongPressGestureRecognizer) { 
     if sender.state == UIGestureRecognizerState.Began { 
      let location = sender.locationInView(self.MapView) 
      let locCoord = self.MapView.convertPoint(location, toCoordinateFromView: self.MapView) 
      let annotation = MKPointAnnotation() 

      annotation.coordinate = locCoord 
      annotation.title = "City Name" 
      annotation.subtitle = "" 

      self.MapView.removeAnnotations(MapView.annotations) 
      self.MapView.addAnnotation(annotation) 
      self.MapView.selectAnnotation(annotation, animated: true) 


     } 
     func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { 
      if control == view.rightCalloutAccessoryView { 
       self.performSegueWithIdentifier("mapseg", sender: self) 

      } 
     } 

    } 

} 
+0

これを取得するために使用したprepareForSequeコードを投稿できますか? – cfsprod

答えて

1

prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)メソッドをオーバーライドする必要があると思います。そして、動作しているかどうかを確認してください。

+0

ああ大丈夫です! prepareForSegue関数の本体にコードを記述する必要がありますか、空のままにしておく必要があるのでしょうか? – Straxis

+0

私はsegueを実行する責任を負う関数のすぐ下にオーバーライド関数を置こうとしましたが、エラーメッセージが表示されました。さらに調べると、私はdropPin関数に閉じ中括弧を入れていないことが分かりました。これは、右のアクセサリボタンが押されたときに呼び出されないdropPin関数の中に、セグメンテーションの原因となる関数が含まれていました。これで、中括弧を修正して、prepareForSegue関数を追加しました。どうもありがとうございます!好奇心の外に、prepareForSegue関数は何をしますか? – Straxis

+0

プッシュまたは提示されているUIViewControllerにデータまたはオブジェクトを渡す場合に使用します。 – RBN

関連する問題