【发布时间】:2012-02-25 00:28:58
【问题描述】:
我在 UIView 子类中有一个 MKMapView 实例,它通过实现viewForAnnotation:(id<MKAnnotation>) annotation 方法符合 MKMapViewDelegate 协议。其中的代码是:
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[DriverLocation class]]) {
MKAnnotationView* a = [self.map dequeueReusableAnnotationViewWithIdentifier:@"driverView"];
if (a == nil) {
MKAnnotationView* a = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"driverView"];
a.enabled = YES;
a.image = [UIImage imageNamed:@"car.png"];
}
return a;
}
return nil;
}
图像未正确加载 - 加载的图像属性的高度和宽度为零,并且 MKAnnotationView 实例 a 的尺寸也为零。
图片为 4Kb png 32 像素 x 32 像素。
我可以确认图像已经被复制到模拟器的根 .app 目录中。
任何关于为什么不加载的帮助将不胜感激!
【问题讨论】:
-
对不起。我是个白痴。我创建了两个名为 a 的变量,if 语句中 a 的实例化应该只是 a = ... 而不是 MKAnnotationView* a。
标签: iphone ios mkmapview mkannotationview