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