2014-01-08 2 views
0

Google지도 API를 통해 특수 효과에 현재로드 한 데이터를 스토리 보드를 통해 세부보기 컨트롤러를 통해 전달하려고합니다.스토리 보드를 사용하여 특수 효과에서 상세보기 iOS로 데이터 전달

각 주석의 상세 정보 공개를 클릭하면 상세보기 컨트롤러가 제대로로드되지만 현재 전달 된 데이터를 가져 오려고합니다.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
// Assuming I call the MapPoint class here and set it to the current annotation 
// then I'm able to call each property from the MapPoint class but wouldn't 
// I have to set this in the prepareForSegue but that would be out of scope? 

    MapPoint *annView = view.annotation; 

    // annView.name 
    // annView.address 

    [self performSegueWithIdentifier:@"showBarDetails" sender:view]; 
} 
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([[segue identifier] isEqualToString:@"showBarDetails"]) 
    { 
     BarDetailViewController *bdvc = [self.storyboard instantiateViewControllerWithIdentifier:@"showBarDetails"]; 
     //This parts confusing me, not sure how I obtain the data 
     // from the above mapView delegation method? 
     // annView.name = bdvc.name; 
     bdvc = segue.destinationViewController; 

    } 
} 
+0

난 쉽게 스토리 보드와 펜촉 ..를 사용하지 않고이 작업을 수행 할 수있어하지만 난에 노력하고있어 순수 스토리 보드 사용법을 배웁니다. – user3117785

답변

5

위임 방법

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    [self performSegueWithIdentifier:@"showBarDetails" sender:view]; 
} 

prepareForSegue에서 mapView에서 :

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([[segue identifier] isEqualToString:@"showBarDetails"]) 
    { 
     MapPoint *annotation = (MapPoint *)view.annotation; 

     BarDetailViewController *bdvc = segue.destinationViewController; 
     bdvc.name = annotation.name; 
     bdvc.otherProperty = annotation.otherProperty; 

    } 
} 
+0

왜 추가 속성이 필요합니까? prepareForSegue에서 'sender'는 주석보기이므로 sender.annotation을 사용하여 주석을 가져올 수 있습니다. http://stackoverflow.com/questions/14805954/mkannotationview-push-to-view-controller-when-detaildesclosure-button-is-clicked를 참조하십시오. (그런데 segue에 관계없이 맵보기에는 선택된 애노테이션이 무엇인지 알려주는 selectedAnnotations 속성이 이미 있습니다. 따라서 추가 속성이 필요하지 않습니다.) – Anna

+0

@Anna 감사합니다 :) 내 대답을 업데이트했습니다. –

관련 문제