iPhone 不同的标注有不同的图像

发布于 2024-10-21 23:58:36 字数 138 浏览 1 评论 0原文

我正在 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 技术交流群。

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

发布评论

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

评论(1

反差帅 2024-10-28 23:58:36

在地图的 viewForAnnotation: 方法中设置 leftCalloutAccessoryView。 leftCallout 是一个 UIView,因此您可以在其中放置任何内容。一些示例代码可能如下所示:

        MKAnnotationView *av = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                 reuseIdentifier:@"ReuseMe"] autorelease];
        [av setCanShowCallout:YES]; 
        UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SFIcon.png"]];
        av.leftCalloutAccessoryView = sfIconView;
        [sfIconView release];  

查看 Apple 的 MapCallouts 演示代码。它做你想做的事。

根据评论更新:要更改图像,只需在 initWithImage 中放入新图像即可。你可以让该行类似于

UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[myArrayOfImages objectAtIndex:myIndexVariable]];

您甚至可以将从 UIImageView 开始的行一直重构到 [sfIconView,并以这种方式传递图像。 viewForAnnotation: 的代码会针对每个注释调用一次(就像 UITableView 中的单元格一样)。

Set the leftCalloutAccessoryView in your viewForAnnotation: method of the Map. The leftCallout is a UIView so you can put anything there. Some sample code might look like:

        MKAnnotationView *av = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                 reuseIdentifier:@"ReuseMe"] autorelease];
        [av setCanShowCallout:YES]; 
        UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SFIcon.png"]];
        av.leftCalloutAccessoryView = sfIconView;
        [sfIconView release];  

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 for viewForAnnotation: gets called one time for each annotation (just like the cells in a UITableView).

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