将Disclosure Button添加到MKPointAnnotation [英] Add Disclosure Button to MKPointAnnotation

查看:91
本文介绍了将Disclosure Button添加到MKPointAnnotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在故事板iOS项目中创建地图注释,我使用了:

To create a map annotation in a storyboard iOS project, I used:

    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推到新的查看控制器和显示图像。这可能吗?

It works great but I'd like to add a disclosure button so I can push seque to a new view controller and display image. Is this possible?

提前Thx,

- bd -

--bd--

推荐答案

将您的类声明为 MKMapViewDelegate 。然后,添加

declare your class to be a MKMapViewDelegate. Then, add

- (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-files ...)

... ViewController can be anything you defined (I use nib-files...)

这篇关于将Disclosure Button添加到MKPointAnnotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆