好的,我有一个带注释的地图视图,点击后,他们会在右侧显示带有标注图标的标注。点击时,此函数称为:
- (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
最佳答案
在您的情况下,发件人是标注按钮(不是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...
}
关于iphone - 发件人时提取MKAnnotation标注的标题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4339445/