自定义注释视图的图像不会出现在 MKMapView 中的设备构建上

发布于 2024-09-07 12:50:23 字数 1082 浏览 0 评论 0原文

我正在使用 iphone sdk 并尝试在 MKMapView 上为 AnnotationView 使用自定义图像。我的方法适用于我的应用程序中的另一个屏幕,但对于有问题的屏幕,我在模拟器中看到图像,但在设备上看不到图像。我基本上创建一个像这样的自定义视图:

@implementation CustomAnnotationView

- (id) initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [ super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier ])
    {
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

        self.image = [UIImage imageNamed:@"MapIcon.png"];

    }
    return self;
}

@end

然后在 getViewForAnnotation 方法中我这样做:

    // attempt to reuse
    CustomAnnotationView* annotationView = (Custom AnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@""];

    // if reuse failed, create a new one
    if (annotationView == nil)
    {
        annotationView = [[Custom AnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""];
    }

    return annotationView;

它在模拟器中工作,但在设备中不起作用。如果我停止使用自定义视图,它将在两者中放置红色图钉(即它有效)。有人见过这样的差异吗?

I am using the iphone sdk and trying to use a custom image for my AnnotationView on my MKMapView. My approach works fine for another screen in my app, but for the problematic one, I see the image in the simulator but not on the device. I basically create a custom view like this:

@implementation CustomAnnotationView

- (id) initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [ super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier ])
    {
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

        self.image = [UIImage imageNamed:@"MapIcon.png"];

    }
    return self;
}

@end

Then in the getViewForAnnotation method I do this:

    // attempt to reuse
    CustomAnnotationView* annotationView = (Custom AnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@""];

    // if reuse failed, create a new one
    if (annotationView == nil)
    {
        annotationView = [[Custom AnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""];
    }

    return annotationView;

It works in the simulator but never in the device. If I stop using a custom view it places the red pin in both (i.e. it works). Has anyone seen a discrepancy like this?

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

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

发布评论

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

评论(1

水染的天色ゝ 2024-09-14 12:50:23

哇。我发现问题是 MapIcon.png 不存在。这解释了为什么它在设备上不起作用,但它没有解释我如何设法在模拟器中看到该图标。也许以某种扭曲的方式它找到了项目中的 MapIconLocale.png 文件。或者项目中可能有一些跟踪资源,因为我几周前曾经有一个 MapIcon.png 并删除了它(以某种方式删除了它)?

不管怎样,正确命名的图像显然可以解决这个问题。

Wow. I discovered that the problem was that MapIcon.png does not exist. That explains why it did not work on the device, but it doesn't explain how I managed to see the icon in the simulator. Perhaps in some twisted way it found the MapIconLocale.png file which is in the project. Or could there be some trace asset in the project because I used to have a MapIcon.png weeks ago and removed it (a copy somehow)?

Either way, having the correctly named image obviously fixed it.

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