发件人时提取 MKAnnotation 标注的标题

发布于 2024-10-06 05:41:56 字数 1152 浏览 3 评论 0原文

好的,我有一个带有注释的地图视图,当点击时,它们会在右侧显示带有公开图标的标注。点击时,将调用此函数:

- (void)showDetails:(id)sender
{
    NSLog(@"showDetails: called!");
    NSLog(@"sender: %@",sender);
    PermitDetailViewController *permitDetail = [[PermitDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    NSLog(@"permitDetail.title: %@",permitDetail.title);
    permitDetail.title = sender.title; //compiler doesn't like this!
    NSLog(@"permitDetail.title: %@",permitDetail.title);
    [self.navigationController pushViewController:permitDetail animated:YES];
    [permitDetail release];
}

到目前为止一切都很好,但我需要知道标注的标题是什么。我正在尝试执行 sender.title 但效果不佳...有什么想法吗?

这是当我将有问题的行更改为 permitDetail.title = self.title; 时的控制台输出:

2010-12-02 11:50:06.044 Parking[55413:207] showDetails: called!
2010-12-02 11:50:06.045 Parking[55413:207] sender: <UIButton: 0x8139890; frame = (104 8; 29 31); opaque = NO; autoresize = LM; layer = <CALayer: 0x8139920>>
2010-12-02 11:50:06.045 Parking[55413:207] permitDetail.title: (null)
2010-12-02 11:50:06.045 Parking[55413:207] permitDetail.title: All Permits

Ok guys, so I have a map view with annotations and when tapped, they display callouts with a disclosure icon on the right. When tapped, this function is called:

- (void)showDetails:(id)sender
{
    NSLog(@"showDetails: called!");
    NSLog(@"sender: %@",sender);
    PermitDetailViewController *permitDetail = [[PermitDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    NSLog(@"permitDetail.title: %@",permitDetail.title);
    permitDetail.title = sender.title; //compiler doesn't like this!
    NSLog(@"permitDetail.title: %@",permitDetail.title);
    [self.navigationController pushViewController:permitDetail animated:YES];
    [permitDetail release];
}

All well and good so far, but I need to know what the callout's title was. I am trying to do sender.title but that ain't working to well... Any ideas?

This is the console output when I change the problematic line to permitDetail.title = self.title;:

2010-12-02 11:50:06.044 Parking[55413:207] showDetails: called!
2010-12-02 11:50:06.045 Parking[55413:207] sender: <UIButton: 0x8139890; frame = (104 8; 29 31); opaque = NO; autoresize = LM; layer = <CALayer: 0x8139920>>
2010-12-02 11:50:06.045 Parking[55413:207] permitDetail.title: (null)
2010-12-02 11:50:06.045 Parking[55413:207] permitDetail.title: All Permits

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

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

发布评论

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

评论(1

浪荡不羁 2024-10-13 05:41:56

您的情况下的发送者是标注按钮(不是 MKAnnotation),因此它没有 title 属性。

在 viewForAnnotation 中,删除公开按钮上的 addTarget。只需将注释视图的 rightCalloutAccessoryView 设置为按钮即可。

然后实现 calloutAccessoryControlTapped 委托方法,该方法将在点击标注时调用。它还提供了对调用中注释视图的引用。注释视图包含对注释的引用:

- (void)mapView:(MKMapView *)mapView 
        annotationView:(MKAnnotationView *)view 
        calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"callout annotation.title = %@", view.annotation.title);

    //do your show details thing here...
}

The sender in your case is the callout button (not the MKAnnotation) so it doesn't have the title property.

In viewForAnnotation, remove the addTarget on the disclosure button. Just set the annotation view's rightCalloutAccessoryView to be the button.

Then implement the calloutAccessoryControlTapped delegate method which will be called when the callout is tapped. It also provides a reference to the annotation view in the call. The annotation view contains a reference to the annotation:

- (void)mapView:(MKMapView *)mapView 
        annotationView:(MKAnnotationView *)view 
        calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"callout annotation.title = %@", view.annotation.title);

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