1
votes

I'm trying hook up a detail disclosure indicator on a map annotation view to a segue. For some reason it's crashing. FYI - I've had this working from a UIButton (with a control drag connection made in the Storyboard).

The error I'm getting with the following code is "unrecognized selector sent to instance".

Here's the MKAnnotationView code with the detail disclosure indicator:

 - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
    {
        MKPinAnnotationView *mapPin = nil;
        if(annotation != map.userLocation) 
        {
            static NSString *defaultPinID = @"defaultPin";
            mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
            if (mapPin == nil )
            {
                mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                                                          reuseIdentifier:defaultPinID];
                mapPin.canShowCallout = YES;

                UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                [disclosureButton addTarget:self action:@selector(prepareForSegue:) forControlEvents:UIControlEventTouchUpInside];

                mapPin.rightCalloutAccessoryView = disclosureButton;

            }
            else
                mapPin.annotation = annotation;

        }
        return mapPin;
    }

Here's the prepareForSegue method:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        // Make sure we're referring to the correct segue
        if ([[segue identifier] isEqualToString:@"ShowMoreInfo"]) {

            // Get reference to the destination view controller
            MoreDetailViewController *mdvc = [segue destinationViewController];


            [mdvc setSelectedItemName:[NSString stringWithFormat:@"%@", placeName.text]];
            [mdvc setSelectedItemAddress:[NSString stringWithFormat:@"%@", placeFormattedAddress.text]];

            [mdvc setSelectedItemWeb:[NSString stringWithFormat:@"%@", placeWebsite.text]];
            [mdvc setSelectedItemRating:[NSString stringWithFormat:@"%@", placeRating.text]];
      //      [mdvc setSelectedItemDistance:[NSString stringWithFormat:@"%@", placeDistance.text]];

        }
    }
2

2 Answers

1
votes

You don't explicity call the prepareForSegue method, what you should do is create another method that performs the change of the segue. Something like this:

You have to change your mapView:map viewForAnnotation:annotation method change this line

 [disclosureButton addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];

Then in your method you perform the change of the view

 -(void)myMethod{ 
[self performSegueWithIdentifier:@"ShowMoreInfo" sender:self];
 }

I think that should work.

1
votes

I suspect you would be helped by using mapView:didSelectAnnotationView: and then mapView:annotationView:calloutAccessoryControlTapped: after the annotation is presented and the callout selected.