![](/img/trans.png)
[英]How do I pass information from a table view cell in one view controller to another view controller?
[英]How do you pass id from a view controller with a map view to another view controller?
我正在使用解析来检索数据,如何将具有映射视图的viwecontroller的对象ID传递给另一个视图控制器,
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
[self performSegueWithIdentifier:@"MapToDeal" sender:view.annotation];
NSLog(@"%@",view.annotation.title);
}
在.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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.