0
votes

I have a mapview that fetches from coredata and gets an array of Location objects. Location objects are custom NSManagedObjects that look like this:

@property (nonatomic, retain) NSString * ciudad;
@property (nonatomic, retain) NSString * horario;
@property (nonatomic, retain) NSString * codigo;
@property (nonatomic, retain) NSString * nombrePublico;
@property (nonatomic, retain) NSString * telefono;
@property (nonatomic, retain) NSString * direccion;
@property (nonatomic, retain) NSString * coordenadas;
@property (nonatomic, retain) NSString * hrs24;
@property (nonatomic, retain) NSString * driveThru;
@property (nonatomic, retain) NSDate * updatedAt;

I then loop thru all Location objects in the array and create Annotations like so:

MyLocation *annotation = [[MyLocation alloc] initWithName:storeDescription address:address coordinate:coordinate distance:0];

And I add those annotations to an array and later plot them at the touch of a button:

- (IBAction)refreshTapped:(id)sender {
    for (id<MKAnnotation> annotation in _mapView.annotations) {
        [_mapView removeAnnotation:annotation];
    }
    for (MyLocation *annotation in self.myLocationsToSort) {
        [_mapView addAnnotation:annotation];   
    }   
}

Finally I want to pass the object to a UIViewController once the user taps the disclosure button on the callout. So first I create my annotation:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

then I will do this:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{

    if (![view.annotation isKindOfClass:[MyLocation class]])
        return;

    [self performSegueWithIdentifier:@"DetailVC" sender:view];

}

The segue calls the detail tableview. My question is, how should I handle the passing of the object to the detail tableview?

2

2 Answers

1
votes

In your map view before performSegueWithIdentifier save annotation to a member var then override

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"DetailVC"]) {
        [[segue destinationViewController] setAnnotation:self.annotation];
    }
}
0
votes

Use the prepareForSegue method and pass it :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"DetailVC"])
{
    YourViewController *vc = [segue destinationViewController];

    // Pass objects to the destination
    [vc setAObjectHere:object];
}
}