0

So I am making an app that has an app that makes multiple map annotations using the same custom class. Each annotation currently has a button on it. What I want to do is to have each pin assign a unique value to a variable in the main view controller class. For example, if I pushed the button on pin 1 on the map, some variable in the main view controller would be of the value 1 but if I were to hit button 2 then the variable would have a value 2 etc. Here is the code for my viewController. Notice that there are currently 2 annotations of the custom pin made, GrandCarousel and OrientExpress in the viewDidLoad method.

- (void)viewDidLoad {
[super viewDidLoad];
self.mapView.delegate = self;
self.mapView.mapType = MKMapTypeSatellite;

CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(34.422409, -118.596120);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 1000, 1000)];
[self.mapView setRegion:adjustedRegion animated:YES];

CLLocationCoordinate2D pinLocationGrandCarousel = CLLocationCoordinate2DMake(34.422413, -118.596112);
WOMapAnnotation *GrandCarousel = [[WOMapAnnotation alloc] initWithCoordinate:pinLocationGrandCarousel title:@"Grand Carousel" andSubTitle:nil];
GrandCarousel.selectedSection = 0;
GrandCarousel.selectedRow = 0;
[_mapView addAnnotation:GrandCarousel];

CLLocationCoordinate2D pinLocationOrientExpress = CLLocationCoordinate2DMake(34.422578, -118.596362);
WOMapAnnotation *OrientExpress = [[WOMapAnnotation alloc] initWithCoordinate:pinLocationOrientExpress title:@"Orient Express" andSubTitle:nil];
GrandCarousel.selectedSection = 0;
GrandCarousel.selectedRow = 1;
[_mapView addAnnotation:OrientExpress];
}


- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>) annotation
{
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinLocation"];

newAnnotation.canShowCallout = YES;
newAnnotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

return newAnnotation;
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
NSLog(@"you touched the disclosure indicator for ride");
}

So if you notice, each instance of the WOMapAnnotation class has the custom properties selectedSection and selectedRow along with the normal title and coordinates. The button appears exactly as I would like it to, but the button does the exact same thing is. So my overall question is how would I access the properties selectedRow and selectedSection in the viewController class dependent on the annotation tapped? Any help would be great!

woakley5
  • 304
  • 3
  • 17
  • 1
    Do you mean how to tell which annotation is calling calloutAccessoryControlTapped? See http://stackoverflow.com/questions/22572342/how-to-access-to-an-annotation-attribute-inside-method-calloutaccessorycontrolta for one example. By the way, after creating OrientExpress, the code is setting the properties of GrandCarousel (again). –  Feb 06 '15 at 03:31
  • Alright, I think that's exactly what I'm looking for. What do you mean by the 2nd part of your answer? Sorry if this is a simple question but this is the first time I've used MapKit. – woakley5 Feb 06 '15 at 03:53
  • In viewDidLoad, after alloc+init of OrientExpress, code is setting GrandCarousel properties instead of OrientExpress. –  Feb 06 '15 at 04:04
  • Oh whoops! I see what you're saying, just forgot to change it after the copy paste – woakley5 Feb 06 '15 at 04:05

0 Answers0