如何在我的 Pin 注释上显示标题并使其可单击以执行某些操作?

发布于 2024-11-26 05:56:42 字数 82 浏览 1 评论 0原文

在我的 MapView 中,我在某些位置放置了图钉,现在我想在这些图钉注释上显示一些标题并使其可单击,以便单击时我可以推送另一个视图。 请帮忙!!!!

In my MapView i have pin dropped on certain locations and now i want to display some title on these pin annotation and make it clickable so that on click i can push another view.
Please help !!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亽野灬性zι浪 2024-12-03 05:56:42

这是代码片段:

使用此方法的自定义注释视图

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    if (annotation == mapView.userLocation) return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];
    if (pin == nil)
    {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"asdf"] autorelease];
    }
    else
    {
        pin.annotation = annotation;
    }
    pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pin.pinColor = MKPinAnnotationColorRed;
    pin.animatesDrop = YES;
    [pin setEnabled:YES];
    [pin setCanShowCallout:YES];
    return pin;

}

点击按钮时调用的委托方法

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{

    //DetailPg=[[BookMarksDetail alloc]initWithNibName:@"BookMarksDetail" bundle:nil];
    //DetailPg.selectRest =[view.annotation title]; //In addition, to get the Title of the AnnotationView.
    //DetailPg.m=1;
    //[self.navigationController pushViewController:DetailPg animated:YES];
    //[DetailPg release];

}

This is the code snippet:

Custom Annotation View using this method

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    if (annotation == mapView.userLocation) return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];
    if (pin == nil)
    {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"asdf"] autorelease];
    }
    else
    {
        pin.annotation = annotation;
    }
    pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pin.pinColor = MKPinAnnotationColorRed;
    pin.animatesDrop = YES;
    [pin setEnabled:YES];
    [pin setCanShowCallout:YES];
    return pin;

}

Delegate method which get's called when you tap on the button

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{

    //DetailPg=[[BookMarksDetail alloc]initWithNibName:@"BookMarksDetail" bundle:nil];
    //DetailPg.selectRest =[view.annotation title]; //In addition, to get the Title of the AnnotationView.
    //DetailPg.m=1;
    //[self.navigationController pushViewController:DetailPg animated:YES];
    //[DetailPg release];

}
梦初启 2024-12-03 05:56:42

Apple 文档中提供了所有这些问题的答案,我建议您仔细阅读它们。然而,要进行调出,您所需要做的就是设置标题属性。

对于按钮等,您需要使用 MapView Delegate 方法:

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

_pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

Apple 建议重用注释,这是您需要考虑的事情。

The answers to this are all provided in Apples Docs I suggest you read them more closely. However to have a call out all you need to do is set the title property.

For buttons and such you need to use the MapView Delegate method:

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

_pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

Apple suggests reusing annotations this is something you will need to take into account.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文