2

我有一个程序,它使用 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 方法的信息都将不胜感激。

4

1 回答 1

0

使用获取注释的标题

let someTitle = sender!.title!!

然后使用 someTitle 搜索/过滤图片、建筑物名称(或您要查找的任何其他内容)的数据。

于 2016-03-04T23:18:07.547 回答