好的,所以我有一个带注释的地图视图,当点击时,它们会在右侧显示带有披露图标的标注。点击时,会调用此函数:
- (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
答案 0 :(得分: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...
}