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!