I am trying to present another view controller once the right callout button is pressed but it must go to the correct indexPath, similar to how this happens in a table view. this is where I am up to:
I have created a custom annotation like so:
class annotationCustom: NSObject, MKAnnotation {
var coordinate : CLLocationCoordinate2D
var title : NSString!
var subtitle : NSString!
var isUserAnnotation : Bool
var dataImage = [NSData]()
init(coordinate: CLLocationCoordinate2D, title: NSString!, subtitle: NSString!){
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
self.isUserAnnotation = false
}
}
and then set the viewForAnnotation
like so:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
var dqPin = "pin"
var view = mapView.dequeueReusableAnnotationViewWithIdentifier(dqPin) as? MKPinAnnotationView
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: dqPin)
view!.canShowCallout = true
var arrowBut = UIImage(named: "arrow")
var arrowButton = UIButton()
arrowButton.setImage(arrowBut, forState: UIControlState.Normal)
arrowButton.tintColor = UIColor.blackColor()
arrowButton.frame = CGRectMake(0, 0, 30, 30)
view!.rightCalloutAccessoryView = arrowButton
}
return view
}
Now I know I have to use the function:
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView {
let sb = UIStoryboard(name: "Main", bundle: nil)
let userProfileVC = sb.instantiateViewControllerWithIdentifier("usersProfileVC") as UsersProfilesViewController
userProfileVC.profileName = annotationCustom.title // error: 'annotationCustom.Type' does not have a member named 'title'
performSegueWithIdentifier("goToUserFromMap", sender: self)
}
}
}
Can somebody fill in the gaps or help me out please.
Thanks