iPhone 不同的标注有不同的图像
我正在 iPhone 中开发一个处理地图的应用程序。我有很多注释。我需要在每个注释的标注(左侧附件视图)中加载不同的图像。谁能告诉我该怎么做。用户在需要时动态添加注释,并从图库中选择图像以将其添加到特定的注释标注中。我可以将图像添加到标注中。但无法区分不同的注释
I am developing an application in iphone which deals with maps. I have many annotations. I need different images to be loaded in the callout(left accessory view) for each of these annotations. Can anyone please tell me how to do this. The user adds annotations dynamically when needed and chooses a image from the gallery to add it to that particular annotation callout. I am able to add images to callouts. but not able to differentiate it for different annotations
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在地图的
viewForAnnotation:
方法中设置leftCalloutAccessoryView
。 leftCallout 是一个 UIView,因此您可以在其中放置任何内容。一些示例代码可能如下所示:查看 Apple 的 MapCallouts 演示代码。它做你想做的事。
根据评论更新:要更改图像,只需在 initWithImage 中放入新图像即可。你可以让该行类似于
UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[myArrayOfImages objectAtIndex:myIndexVariable]];
您甚至可以将从
UIImageView
开始的行一直重构到[sfIconView
,并以这种方式传递图像。viewForAnnotation:
的代码会针对每个注释调用一次(就像 UITableView 中的单元格一样)。Set the
leftCalloutAccessoryView
in yourviewForAnnotation:
method of the Map. The leftCallout is a UIView so you can put anything there. Some sample code might look like:Review the MapCallouts demo code from Apple. It does what you want.
UPDATE BASED on Comment: to change out the image just put in a new image in initWithImage. you could have the line be something like
UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[myArrayOfImages objectAtIndex:myIndexVariable]];
You could even refactor the lines that start
UIImageView
all the way to[sfIconView
and pass in the image that way. The code forviewForAnnotation:
gets called one time for each annotation (just like the cells in a UITableView).