I've read most of the other questions here, as well as read a lot, but I'm not finding an answer.
I'm using this code to create the buttons
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
NSLog(@"called the MKAnnotView method, tag is: %i", self.tag);
static NSString *s = @"ann";
MKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:s];
if (!pin) {
pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:s];
pin.canShowCallout = YES;
pin.calloutOffset = CGPointMake(0, 0);
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.tag=self.tag++;
[button addTarget:self
action:@selector(viewDetails:)
forControlEvents:UIControlEventTouchUpInside];
pin.rightCalloutAccessoryView = button;
}
return pin;
}
-(void) viewDetails: (id) sender {
UIButton *button = sender;
NSLog(@"viewDetails called with button.tag: %i",button.tag);
//[self performSegueWithIdentifier:@"detailView" sender:self];
}
I'm creating a variable amount of pins, in a specific order. When I create them, I get the expected output of "called the MKAnnotView method, tag is 0" then 1, 2, 3, etc.
The annotations are in a very specific order. Zeroth, first, second, so forth. I expect the buttons I created for each annotation to have a tag that fits their index, so that when I segue to the detailViewController, I know which item on the list needs to be pulled and the view populated.
That's not happening. The buttons are each getting randomly assigned tags that repeat. My last case had two tags with 3, and two with zero.
I cannot for the life of me understand why.
Any hints?