5

为了在 Storyboard iOS 项目中创建地图注释,我使用了:

    CLLocationCoordinate2D annotationCoord3;

        annotationCoord3.latitude = 34.233129;
        annotationCoord3.longitude = -118.998644;

        MKPointAnnotation *annotationPoint3 = [[MKPointAnnotation alloc] init];
        annotationPoint3.coordinate = annotationCoord3;
        annotationPoint3.title = @"Another Spot";
        annotationPoint3.subtitle = @"More than a Fluke";
        [_mapView addAnnotation:annotationPoint3];

它工作得很好,但我想添加一个披露按钮,这样我就可以将序列推送到一个新的视图控制器并显示图像。这可能吗?

提前谢谢,

--bd--

4

2 回答 2

9

将您的班级声明为MKMapViewDelegate. 然后加

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {


    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"String"];
    if(!annotationView) {   
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"String"];
        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;

    return annotationView;
}

然后你添加:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    // Go to edit view
    ViewController *detailViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
   [self.navigationController pushViewController:detailViewController animated:YES];

}

... ViewController 可以是您定义的任何内容(我使用 nib 文件...)

于 2012-06-07T19:29:34.833 回答
2

Axel 的回答是正确的(我刚刚投了赞成票):您必须实现MKMapViewDelegate并将其实例分配给DelegateMKMapView 的属性。对于那些使用MonoTouch的人,这里是端口:

class MapDelegate : MKMapViewDelegate
{
    public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
    {
        MKAnnotationView annotationView = mapView.DequeueReusableAnnotation ("String");
        if (annotationView == null) {
            annotationView = new MKAnnotationView(annotation, "String");
            annotationView.RightCalloutAccessoryView = new UIButton(UIButtonType.DetailDisclosure);
        }
        annotationView.Enabled = true;
        annotationView.CanShowCallout = true;
        return annotationView;
    }

    public override void CalloutAccessoryControlTapped (MKMapView mapView, MKAnnotationView view, UIControl control)
    {
        // Push new controller to root navigation controller.
    }
}
于 2012-11-29T00:05:28.917 回答