0

我在地圖上放了幾個別針,例如對應不同的橋位置。當點擊這些引腳時,每個引腳都有自己的註釋,顯示其標題和副標題。我在這些註釋中添加了一個信息按鈕。然而,我不知道如何打開一個新的UiViewController,它將改變顯示在UiViewController上的信息,這取決於按下哪個橋信息按鈕。如何使用標註按鈕打開新的uiviewcontroller。 (斯威夫特)

所以基本上我需要知道如何: 1:按下注釋中的信息按鈕時打開UiViewController。 2:改變UiViewController上關於哪些橋接信息按鈕被按下的信息。

這是我到目前爲止有:

 mapView.delegate = self 



    //bridges 
    var Bridge1 = CLLocationCoordinate2DMake(48.60,2.90) 
    var bridge2 = CLLocationCoordinate2DMake(48.61, 2.91) 
    var bridge3 = CLLocationCoordinate2DMake(48.62, 2.92) 
    var bridge4 = CLLocationCoordinate2DMake(48.63, 2.93) 
    var bridge5 = CLLocationCoordinate2DMake(48.64, 2.94) 
    var bridge6 = CLLocationCoordinate2DMake(48.65, 2.95) 


    var span = MKCoordinateSpanMake(0.4, 0.4) 
    var region = MKCoordinateRegion(center: Bridge1, span: span) 
    mapView.setRegion(region, animated: true) 

    var Bridge1pin = MKPointAnnotation() 
    Bridge1pin.coordinate = Bridge1 
    Bridge1pin.title = "Bridge1" 
    Bridge1pin.subtitle = "This is bridge 1" 
    mapView.addAnnotation(Bridge1pin) 

    var bridge2pin = MKPointAnnotation() 
    bridge2pin.coordinate = bridge2 
    bridge2pin.title = "Bridge2" 
    bridge2pin.subtitle = "This is bridge 2" 
    mapView.addAnnotation(bridge2pin) 

    var bridge3pin = MKPointAnnotation() 
    bridge3pin.coordinate = bridge3 
    bridge3pin.title = "Bridge3" 
    bridge3pin.subtitle = "This is bridge 3" 
    mapView.addAnnotation(bridge3pin) 

    var bridge4pin = MKPointAnnotation() 
    bridge4pin.coordinate = bridge4 
    bridge4pin.title = "Bridge4" 
    bridge4pin.subtitle = "This is bridge 4" 
    mapView.addAnnotation(bridge4pin) 

    var bridge5pin = MKPointAnnotation() 
    bridge5pin.coordinate = bridge5 
    bridge5pin.title = "bridge5" 
    bridge5pin.subtitle = "hello this is bridge 5" 
    mapView.addAnnotation(bridge5pin) 

    var bridge6pin = MKPointAnnotation() 
    bridge6pin.coordinate = bridge6 
    bridge6pin.title = "bridge6" 
    bridge6pin.subtitle = "hello this is bridge 6" 
    mapView.addAnnotation(bridge6pin) 




} 


func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
    let reuseIdentifier = "pin" 
    var pin = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseIdentifier) as? MKPinAnnotationView 
    if pin == nil { 
     pin = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier) 
     pin!.pinColor = .Red 
     pin!.canShowCallout = true 
     pin!.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) 
    } else { 
     pin!.annotation = annotation 
    } 
    return pin 
} 


} 

回答

1

您可以瞭解here in this link.

的不同意見之間的導航和我會給導航的一些提示和準備數據的導​​航。

1.當檢測到橋上

爲此,您只需要實現一個叫標註方法,用戶點擊如下calloutAccessoryControlTapped

func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { 
    performSegueWithIdentifier("info", sender: view) 
    // Above line of code is used for the segue operation between multiple MVCs. 
} 

2.您需要添加賽格瑞操作

這可以通過調速拖動來實現從主視圖到故事板的詳細視圖,並選擇爲在彈出,並在顯示屬性檢查器中添加的標識符信息

3.準備模型抽頭橋

對於此僅覆蓋prepareForSegue方法如下。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    //Just validating by checking the same identifier 
    if (segue.identifier == "info") { 
     if let annotation = sender as? MKAnnotationView { 
      let detailViewController = segue.destinationViewController as! DetailViewController 
      detailViewController.titleText = annotation.annotation?.title ?? "" 
      detailViewController.detaileText = annotation.annotation?.subtitle ?? "" 
     } 
    } 
} 

4.這裏是DetailViewController。

它只是有兩個標籤,現在只是顯示冠軍字幕

import UIKit 
class DetailViewController: UIViewController { 
    @IBOutlet weak var titleLabel: UILabel! 
    @IBOutlet weak var detailLabel: UILabel! 

    var titleText: String? { didSet { updateUI() } } 
    var detaileText: String? { didSet { updateUI() } } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     updateUI() 
    } 

    private func updateUI() { 
     self.titleLabel?.text = self.titleText 
     self.detailLabel?.text = self.detaileText 
    } 
}