You can implement the data loading function in your annotation class. To do that you will need to have a reference to that data in your annotation class.
Your annotation class can be something like
@interface MyAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
MyDataObject *mydataObject;
}
- (id) initWithCoordinate:(CLLocoationCoordinate2D)coord withMyData:(MyDataObject*)aDataObject;
- (void) loadDetailView; // this function will load the data in myDataObject to the DetailView
To get the callout touch, you can implement calloutAccessaryControlTapped function in the controller where you implement MKMapViewDelegate.
The function will be something like
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
MyAnnotation *myAnnotation = (MyAnnotation*)view.annotation;
[myAnnotation loadDetailView];
}
Edit
The implementation of initWithCoordinate will be something like:
@implementation MyAnnotation
....
- (id) initWithCoordinate:(CLLocoationCoordinate2D)coord withMyData:(MyDataObject*)aDataObject{
coordinate = coord; // cannot use "self.coordinate" here as CLLocationCoordinate2D is double instead of object (?)
self.title = <# some name #> // assign some string to the title property
self.mydataObject = aDataObject; // this is your data object
return self;
}
....