2014-06-10 275 views
0

我使用解析來檢索數據,如何傳遞由具有地圖視圖到另一個視圖控制器viwecontroller對象ID,如何將ID從視圖控制器與地圖視圖傳遞到另一個視圖控制器?

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

    [self performSegueWithIdentifier:@"MapToDeal" sender:view.annotation]; 
    NSLog(@"%@",view.annotation.title); 
} 
+0

你可以使用委託和協議。 – lighter

+0

你能幫助一個示例代碼 – mugunthan

+0

你可以參考這個網站http://ios-blog.co.uk/tutorials/how-to-create-an-objective-c-delegate/ – lighter

回答

0

寫入該方法中.m文件

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
if ([[segue identifier] isEqualToString: @"MapToDeal"]) 
    { 
    DetailViewController *detailViewController = [segue destinationViewController]; 

    detailViewController.annotview = sender; //here annoteview is object in DetailViewcontroller 
    } 
} 

或 你也可以這樣做

In mapView Delegate method 

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

In prepareForSegue: 

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

     DetailViewController *dvc = segue.destinationViewController; 
     dvc.name = annotation.name; 
     dvc.anyproperty = annotation.anyproperty; 

    } 
} 
相關問題