带有数据库内容 ID 的 iPhone MKAnnotation

发布于 2024-10-20 08:23:25 字数 952 浏览 0 评论 0原文

我尝试使用 MKMap API 并集成数据库表 ID,以便我可以单击详细信息披露按钮将用户发送到包含更多信息的另一个页面。我在 Apple 网站上浏览了 MKMapKit,寻找一些属性或方法来帮助我解决这个问题,并且浏览了一些教程但没有答案。

我尝试将 id 附加到字幕上下文中,以便我可以在 MKAnnotationView 中检索它,我在其中创建 MKPinAnnotationView 并将按钮添加到 rightCalloutAccessoryView。它出错并且不想工作。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{  

MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"mkpin"];  
annView.animatesDrop = YES;  
annView.canShowCallout = YES;  

UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];  
annView.rightCalloutAccessoryView = disclosureButton;  

return annView;  

将这种技术用于地图上的单个图钉,它似乎有效,但我不需要 id...

当我尝试获取注释的副标题时,它会终止应用程序。我知道(id)注释是一个整数,但我不知道如何操作这些信息。我认为上面的这个函数是在我的代码之后调用的:

[mapView addAnnotations:markers]; //其中标记是标题数组,副标题又名 id

任何帮助将不胜感激。

Im trying to use the MKMap API and integrate a database table id so I can click a button detail disclosure to send the user to another page with further information. Ive been all over teh MKMapKit on the Apple site to find some property or method to help me with this and went over a few tutorials with no answers.

Ive tried to attach the id into the subtitle context so I can retrieve it in the MKAnnotationView where I make my MKPinAnnotationView and add teh button to the rightCalloutAccessoryView. It errors out and doesnt want to work.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{  

MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"mkpin"];  
annView.animatesDrop = YES;  
annView.canShowCallout = YES;  

UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];  
annView.rightCalloutAccessoryView = disclosureButton;  

return annView;  

}

I used this technique for an individual pin on a map and it seemed to work but I didnt require an id...

When I try to get the subtitle of the annotation it kills the app. I know the (id)annotation is an integer but I dont know how to manipulate this information. This function above I think is called after my code:

[mapView addAnnotations:markers]; //where markers is an array of title, subtitle aka id

Any help would be greatly appreciated.

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

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

发布评论

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

评论(1

喜你已久 2024-10-27 08:23:25

subtitle 属性用于副标题,而不是数据库 ID。以这种方式滥用它不会有任何好处。即使你能让它发挥作用,这也是一种可怕的方法。

您所要做的就是为您的注释类提供一个适当的属性来存储您的 id。当您传递注释时,您可以通过转换为注释类来访问它。当您在其他委托方法中传递注释视图时,您可以通过其 annotation 属性访问该注释。

The subtitle property is for a subtitle, not a database id. No good can come from abusing it in that way. Even if you could get it to work, it's a horrible approach.

All you have to do is give your annotation class an appropriate property to store your id. When you are passed the annotation, you can access it from there by casting to your annotation class. When you are passed the annotation view in other delegate methods, you can access the annotation through its annotation property.

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