Im trying to create a button within each annotation view to bring the user to a new page custom to the selected annotation. I've successfully implemented the mapview to show the annotations with titles and subtitles loaded from my parse database but am struggling to find a way of 1) adding a button to the annotation view to bring the user to a new view 2) finding a way of creating custom views for each of the annotations when selected. Any help would be greatly appreciated ?
Code
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
var MapViewLocationManager:CLLocationManager! = CLLocationManager()
let btn = UIButton(type: .DetailDisclosure)
override func viewDidLoad() {
super.viewDidLoad()
mapView.showsUserLocation = true
mapView.delegate = self
MapViewLocationManager.delegate = self
MapViewLocationManager.startUpdatingLocation()
mapView.setUserTrackingMode(MKUserTrackingMode.Follow, animated: true)
}
override func viewDidAppear(animated: Bool) {
let annotationQuery = PFQuery(className: "Clubs")
annotationQuery.findObjectsInBackgroundWithBlock {
(clubs, error) -> Void in
if error == nil {
// The find succeeded.
print("Successful query for annotations")
// Do something with the found objects
let myClubs = clubs! as [PFObject]
for club in myClubs {
//data for annotation
let annotation = MKPointAnnotation()
let place = club["location"] as? PFGeoPoint
let clubName = club["clubName"] as? String
let stadiumName = club["stadium"] as? String
annotation.title = clubName
annotation.subtitle = stadiumName
annotation.coordinate = CLLocationCoordinate2DMake(place!.latitude,place!.longitude)
//add annotations
self.mapView.addAnnotation(annotation)
}
} else {
// Log details of the failure
print("Error: \(error)")
}
}
}