Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将披露按钮添加到MKPointAnnotation_Ios - Fatal编程技术网

Ios 将披露按钮添加到MKPointAnnotation

Ios 将披露按钮添加到MKPointAnnotation,ios,Ios,要在故事板iOS项目中创建地图注释,我使用了: CLLocationCoordinate2D annotationCoord3; annotationCoord3.latitude = 34.233129; annotationCoord3.longitude = -118.998644; MKPointAnnotation *annotationPoint3 = [[MKPointAnnotation alloc] init];

要在故事板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];
它工作得很好,但我想添加一个公开按钮,这样我就可以将seque按到一个新的视图控制器并显示图像。这可能吗

Thx提前


--bd--

将您的类声明为
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;
}
。。。ViewController可以是您定义的任何内容(我使用nib文件…)

Axel的答案是正确的(我刚刚投票):您必须实现
MKMapViewDelegate
,并将其实例分配给MKMapView的
Delegate
属性。对于使用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.
    }
}

仅在添加
[mapView setDelegate:self]时有效
viewDidLoad()中的某处左右:)是的。在oredr中,要使用mapview委托方法,您需要首先在.h中符合mkmapviewdelegate,并将viewcontroller设置为mapview的委托。。。希望我能帮助您将内容添加到注释视图,而不是注释;)
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.
    }
}