You can access data from the MKAnnotationView
provided in
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
The view
object has an annotation
property that will give you an object adopting the MKAnnotation
protocol. This could be MKPointAnnotation
as you already have, if just a title
and subtitle
will do. But you could also define a custom annotation class that holds onto a status
and a company
:
MyAnnotation *annotation = view.annotation;
// annotation.status
// annotation.company
You'd have to create a MyAnnotation
instance and insert the data in the place where you currently are creating newAnnotation
.
As for once you have the data you need and you want to pass it to the DetailViewController, I suggest looking at this SO answer or Ole Begemann's tips here. In short, you can create a public property of your detail view controller, and then do something like:
DetailViewController *destinationController = [[DestinationViewController alloc] init];
destinationController.name = annotation.status;
[self.navigationController pushViewController:destinationController animated:YES];
In summary, your method could then look something like this:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
MyAnnotation *annotation = view.annotation;
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:nil
bundle:nil];
detail.status = annotation.status;
detail.company = annotation.company;
[self.navigationController pushViewController:detail animated:YES];
}
And then set the UILabel
texts in your detail view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
self.statusTextField.text = self.status;
self.companyTextField.text = self.company;
}
Update to clarify the creation of MyAnnotation
:
You always have the option of creating a custom class. Here could be an example for MyAnnotation.h
:
#import <MapKit/MapKit.h>
@interface MyAnnotation : MKPointAnnotation
@property (strong, nonatomic) NSString *status;
@property (strong, nonatomic) NSString *company;
@end
Then in your map view controller import: #import "MyAnnotation.h"
and use MyAnnotation
instead of MKPointAnnotation
:
// create the annotation
newAnnotation = [[MyAnnotation alloc] init];
newAnnotation.title = dictionary[@"applicant"];
newAnnotation.subtitle = dictionary[@"company"];
newAnnotation.status = dictionary[@"status"];
newAnnotation.company = dictionary[@"company"];
newAnnotation.coordinate = location;
[newAnnotations addObject:newAnnotation];