Как вызвать переход с кнопки раскрытия на булавке карты?

У меня есть приложение, которое отображает булавки на карте.

Каждый вывод использует этот код для отображения кнопки раскрытия сведений, которая при нажатии вызывает метод showDetail, который затем вызывает метод prepareForSegue. Я думаю, здесь много дополнительной работы.

Должен ли я исключить showDetail и просто вызвать метод prepareForSegue? но как мне передать объект MyLocation?

Вот код:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    static NSString *identifier = @"MyLocation";
    if ([annotation isKindOfClass:[MyLocation class]]) {

        //test if mapviewnil
        if (_mapView == nil) {
            NSLog(@"NIL");
        }
        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        } else {
            annotationView.annotation = annotation;
        }

        annotationView.enabled = YES;
        annotationView.canShowCallout = YES;
        annotationView.image=[UIImage imageNamed:@"locale.png"];


        //instatiate a detail-disclosure button and set it to appear on right side of annotation
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [infoButton addTarget:self action:@selector(showDetailView:annotation:) forControlEvents:UIControlEventTouchUpInside];
        annotationView.rightCalloutAccessoryView = infoButton;

        return annotationView;
    }

    return nil;
}

-(void)showDetailView:(id <MKAnnotation>)annotation{

    //Set the data
    MyLocation *sendingLocation = annotation;

    DetailViewController *destinationViewController = segue.destinationViewController;
    destinationViewController.receivedLocation = sendingLocation;
    [self performSegueWithIdentifier: @"DetailVC" sender: self];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"DetailVC"]) {
        NSLog(@"DetailVC called");
    } else {
        NSLog(@"PFS:something else");
    }
}

Спасибо заранее!

Ответы на вопрос(1)

Ваш ответ на вопрос