2016-09-03 13 views
0

プログラミングが比較的新しいので、mapView注釈付きピンのボタンをタップすることによってビュー間の切り替えが必要になります。マップ注釈ボタンを使用したビュー間のスウィフトの切り替え

import UIKit 
import MapKit 
import CoreLocation  

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { 
    //REF 

    @IBOutlet weak var mapView: MKMapView! 
    @IBOutlet weak var bottompnl: UIImageView! 
    @IBAction func mysticsbtn(sender: AnyObject) { 
    } 
    @IBAction func bondibtn(sender: AnyObject) { 
    } 

    //MAP 
    let locationManager = CLLocationManager() 

    //Annotation 
    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { 
     let identifier = "beach" 
     if annotation is Beach { 
      var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) 
      if annotationView == nil { 
       annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier) 
       annotationView!.canShowCallout = true 
       let btn = UIButton(type: .DetailDisclosure) 
       annotationView!.rightCalloutAccessoryView = btn    

      } else { 
       annotationView!.annotation = annotation 
      } 
      return annotationView 
      self.performSegueWithIdentifier("mysticssegue", sender: nil)  
     } 
     return nil  
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let annotations = getMapAnnotations() 

     // Add mappoints to Map 
     mapView.addAnnotations(annotations)  
     mapView.delegate = self 

     //MAP 
     self.locationManager.delegate = self 
     self.locationManager.desiredAccuracy = kCLLocationAccuracyBest 
     self.locationManager.requestWhenInUseAuthorization() 
     self.locationManager.startUpdatingLocation() 
     //MAKES THE DOT 
     self.mapView.showsUserLocation = true 
    } 

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

    // MAP: Location Delegates Methods 
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
     let location = locations.last 
     let centre = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude) 
     let region = MKCoordinateRegion(center: centre, span: MKCoordinateSpan(latitudeDelta: 3, longitudeDelta: 3)) 
     self.mapView.setRegion(region, animated: true) 
     self.locationManager.startUpdatingLocation() 
    }  

    //TO FIND ERROS 
    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) { 
     print("Erros: " + error.localizedDescription)   
    } 

    //MARK:- Annotations 

    func getMapAnnotations() -> [Beach] { 
     var annotations:Array = [Beach]() 

     //load plist file 

     var beaches: NSArray? 
     if let path = NSBundle.mainBundle().pathForResource("beaches", ofType: "plist") { 
      beaches = NSArray(contentsOfFile: path) 
     } 
     if let items = beaches { 
      for item in items { 
       let lat = item.valueForKey("lat") as! Double 
       let long = item.valueForKey("long")as! Double 
       let annotation = Beach(latitude: lat, longitude: long) 
       annotation.title = item.valueForKey("title") as? String 
       annotations.append(annotation) 
      } 
     }   

     return annotations    
    } 
    //END 
} 

答えて

0

あなたがperformSegueWithIdentifierを呼び出す前に、機能mapViewから戻っているように見えます。

return annotationView 
self.performSegueWithIdentifier("mysticssegue", sender: nil) 

これらの2つの行の順序を逆にしてください。また、コードがないメソッドがあることに気付きました。@IBAction

関連する問題