发件人时提取 MKAnnotation 标注的标题
好的,我有一个带有注释的地图视图,当点击时,它们会在右侧显示带有公开图标的标注。点击时,将调用此函数:
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的情况下的发送者是标注按钮(不是 MKAnnotation),因此它没有 title 属性。
在 viewForAnnotation 中,删除公开按钮上的 addTarget。只需将注释视图的 rightCalloutAccessoryView 设置为按钮即可。
然后实现 calloutAccessoryControlTapped 委托方法,该方法将在点击标注时调用。它还提供了对调用中注释视图的引用。注释视图包含对注释的引用:
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: