2

注釈の詳細ビューへのモーダル セグエを作成する UI Detail Disclosure ボタンを使用してマップ注釈を作成するプログラムがあります。アプリケーションは、ストーリーボードを使用して作成されています。

注釈を定義するためのコードは次のとおりです。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PIN"];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

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


    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        pin.animatesDrop = YES;
        return nil;
    }

    else {
        [pin setPinColor:MKPinAnnotationColorPurple];
    }

    pin.rightCalloutAccessoryView = button;
    pin.animatesDrop = YES;
    pin.canShowCallout = YES;

    return pin;
}

calloutAccessoryControlTappedメソッドは次のとおりです。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{

    NewClass *annView = view.annotation;

    AnnotationView *detailView = [[AnnotationView alloc]init];

    detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    detailView.buildingName = [NSString stringWithFormat:@"my dictionary is %@", annView.title];

    detailView.desciptionText = annView.title;

    [self presentViewController:detailView animated:YES completion:nil];

}

最後に、prepareForSegue方法は次のとおりです。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if([segue.identifier isEqualToString:@"ShowMoreInfo"]){

        AnnotationView *destViewController = segue.destinationViewController;

        //destViewController.buildingName = ; set to name of building of selected annotation

        //destViewController.desciptionText = ; set to description of building of selected annotation (from an array or from passed data)

        destViewController.picName = ;

    }
}

callOutAccessoryControlTappedメソッドから情報を取得し、メソッドの値をそれらの値に設定するにはどうすればprepareForSegueよいですか?

ブレークポイントを使用してデータ値を追跡するとannView.title、文字列値が保持されますが、注釈詳細ビューの詳細ビュー コントローラーの値に割り当てられません。

選択したアノテーションからセグエの準備メソッドにデータを渡す方法に関する情報をいただければ幸いです。

4

1 に答える 1