我在一個UIView子類中有一個MKMapView實例,它通過實現viewForAnnotation:(id<MKAnnotation>) annotation
方法符合MKMapViewDelegate協議。其中的代碼是:MKAnnotationView圖像不顯示
- (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實例的尺寸也爲零。
圖像是4Kb png 32像素x 32像素。
我可以確認圖像已被複制到模擬器的根目錄下。
任何幫助,爲什麼這不是加載將不勝感激!
對不起。我是個白癡。我創建了兩個名爲a的變量,在if語句中的實例化應該只是a = ...而不是MKAnnotationView * a。 – Owen 2012-02-25 00:53:31