我有一个程序,它使用 UI Detail Disclosure 按钮创建地图注释,该按钮使模式 segue 到注释的详细视图。该应用程序是使用情节提要创建的。
这是定义注释的代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PIN"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[button addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventTouchUpInside];
if ([annotation isKindOfClass:[MKUserLocation class]]) {
pin.animatesDrop = YES;
return nil;
}
else {
[pin setPinColor:MKPinAnnotationColorPurple];
}
pin.rightCalloutAccessoryView = button;
pin.animatesDrop = YES;
pin.canShowCallout = YES;
return pin;
}
这是calloutAccessoryControlTapped
方法:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
NewClass *annView = view.annotation;
AnnotationView *detailView = [[AnnotationView alloc]init];
detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
detailView.buildingName = [NSString stringWithFormat:@"my dictionary is %@", annView.title];
detailView.desciptionText = annView.title;
[self presentViewController:detailView animated:YES completion:nil];
}
最后,prepareForSegue
方法如下:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"ShowMoreInfo"]){
AnnotationView *destViewController = segue.destinationViewController;
//destViewController.buildingName = ; set to name of building of selected annotation
//destViewController.desciptionText = ; set to description of building of selected annotation (from an array or from passed data)
destViewController.picName = ;
}
}
如何从callOutAccessoryControlTapped
方法中获取信息并将方法中的值设置prepareForSegue
为这些值?
当我使用断点跟踪数据值时,annView.title
保存一个字符串值,但它从未分配给注释详细视图的详细视图控制器中的值。
任何有关如何将数据从选定注释传递到准备 segue 方法的信息都将不胜感激。