Question

Mapkit usage, here is my scenario: When the user chooses one of the pushpins on my map, then selects the callout associated with that pin, the user is to be be brought to another ViewController that will show information pertinent to their selection.

To set data for the destinationViewController, I am using

   prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

This is working but I have an issue where I am not sure which annotation has been selected. The following code illustrates my issue - the code works, but I have it hard coded to "objectAtIndex:0" instead of objectAtIndex:"whatever pin they selected"

    [self.myImageViewController setAddressMessage:  [[self.annotations objectAtIndex:0] houseAddress]];        

In prepareForSegue, how do I know which pin they have selected?

Était-ce utile?

La solution

Not knowing the rest of your code, I'm not sure if this will work but this is how I found the annotation in a similar situation where a button on the annotation view's callout was pressed.

-(void)buttonInCalloutWasTapped:(UIButton *)button {
    if ([[[[button superview] superview] class] isSubclassOfClass:[MKAnnotationView class]]) {
        MKAnnotation *annotation = [(MKPinAnnotationView *)[[button superview] superview] annotation];
        [self.myImageViewController setAddressMessage:  [annotation houseAddress]];
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top