![](/img/trans.png)
[英]Data turns Nil when passing from previous View Controller going to another View Controller using Segue
[英]passing data to another view controller when tapping on annotation
我有一个在地图上显示位置的应用程序。 我想将数据从第一个视图(MapViewController)传递到另一个视图(locationDetailViewController)
我使用下面的代码传递数据,然后将我带到另一个视图。 但是,它不会将可变数组传递给另一个视图控制器...
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{PlaceDetailViewController *det=[[PlaceDetailViewController alloc]init];
det.PlaceDetailMutableArray=PlaceMutableArray;
[self performSegueWithIdentifier:@"DetailView" sender:view];}
提前致谢
尝试这个:
在您的SecondViewController.m上,添加方法(也不要忘记在SecondViewController.h上声明它):
-(void)setValue:(NSMutableArray*)array
{
NSMutableArray *PlaceDetailMutableArray = [[NSMutableArray alloc] init];
PlaceDetailMutableArray = array;
}
在第一个ViewController上,添加以下代码:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"DetailView"]) {
PlaceDetailViewController *det= segue.destinationViewController;
[det setValue: PlaceMutableArray];
}
}
最后,将示例代码更改为:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self performSegueWithIdentifier:@"DetailView" sender:view];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.