2016-09-03 1 views
0

Я относительно новичок в программировании и вам нужна помощь в переключении между видами, нажав кнопку в mapView аннотированный вывод.Swift-segue между видами с помощью кнопки аннотации карты

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

Похоже, что возвращается из функции mapView перед вызовом performSegueWithIdentifier.

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

Попробуйте изменить порядок этих двух линий. Я также заметил, что у вас есть некоторые методы @IBAction, в которых нет кода.