带有数据库内容 ID 的 iPhone MKAnnotation
我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.