2

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

- (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
4

1 回答 1

8

在您的情况下,发件人是标注按钮(不是 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...
}
于 2010-12-02T20:40:53.580 回答