2014-01-08 51 views
0

我試圖通過Google Places API將當前已加載到註釋中的數據傳遞到我通過使用segue的故事板創建的詳細視圖控制器中。將數據從註釋傳遞到詳細視圖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

mapView委託方法

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

prepareForSegue

-(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謝謝:)我更新了我的答案。 –

相關問題