通过Storyboard中的模态segue检索和传递注释数据

时间:2013-01-25 21:01:35

标签: ios ios6 mkannotation uistoryboardsegue

我有一个程序,可以使用UI详细信息披露按钮创建地图注释,该按钮可以模拟注释到详细的注释视图。该应用程序是使用故事板创建的。

以下是定义注释的代码:

- (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方法的任何信息都将不胜感激。

1 个答案:

答案 0 :(得分:0)

使用

获取注释的标题
let someTitle = sender!.title!!

然后使用someTitle搜索/过滤您的数据以获取图片,建筑物名称(或您正在寻找的任何其他内容)。