地图注释赢得';无法在iOS 7中显示

地图注释赢得';无法在iOS 7中显示,ios,objective-c,mkmapview,mkannotationview,Ios,Objective C,Mkmapview,Mkannotationview,我正在使用以下代码向mapView添加注释。问题在于,注释不会出现在iOS 7中,但会出现在iOS 6中 在myviewDidLoad方法中: for (int i=0; i<[self.listingNodesArray count]; i++) { MyAnnotation* annotation= [MyAnnotation new]; CLLocationCoordinate2D coordinate; coordinate.latitude = [[[[

我正在使用以下代码向mapView添加注释。问题在于,注释不会出现在iOS 7中,但会出现在iOS 6中

在my
viewDidLoad
方法中:

for (int i=0; i<[self.listingNodesArray count]; i++) {
    MyAnnotation* annotation= [MyAnnotation new];

    CLLocationCoordinate2D coordinate;
    coordinate.latitude = [[[[self.listingNodesArray objectAtIndex:i] objectForKey:@"address"] objectForKey:@"lat"] doubleValue];
    coordinate.longitude = [[[[self.listingNodesArray objectAtIndex:i] objectForKey:@"address"] objectForKey:@"lng"] doubleValue];

    annView.image = [UIImage imageNamed:@"PIN_img.png"];// sets image for pin

    annotation.coordinate = coordinate;

    annotation.title = [[self.listingNodesArray objectAtIndex:i] objectForKey:@"title"];
    annotation.subtitle = [[[self.listingNodesArray objectAtIndex:i] objectForKey:@"address"] objectForKey:@"address"];

    NSNumber *listingIdNumber = [[self.listingNodesArray objectAtIndex:i] objectForKey:@"id"];

    annotation.catListingMapId = listingIdNumber;

    [self.topMapView addAnnotation: annotation];

}

[self.view addSubview:self.topMapView];
和我的注释文件:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapViewAnnotation : NSObject <MKAnnotation> {

    NSString *title;
    CLLocationCoordinate2D coordinate;

}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;

@end

    #import "MapViewAnnotation.h"

@implementation MapViewAnnotation

@synthesize title, coordinate;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {

    title = ttl;
    coordinate = c2d;
    return self;
}


@end
#导入
#进口
@接口MapViewAnnotation:NSObject{
NSString*标题;
CLLocationCoordinate2D坐标;
}
@属性(非原子,副本)NSString*标题;
@属性(非原子,只读)CLLocationCoordinate2D坐标;
-(id)initWithTitle:(NSString*)ttl和坐标:(CLLocationCoordinate2D)c2d;
@结束
#导入“MapViewAnnotation.h”
@MapViewAnnotation的实现
@综合标题、坐标;
-(id)initWithTitle:(NSString*)ttl和坐标:(CLLocationCoordinate2D)c2d{
标题=ttl;
坐标=c2d;
回归自我;
}
@结束

正如AnnaKarenina所指出的,您应该在注释的
视图
方法中设置注释视图的
图像

这在iOS 6中可能有些“有效”,但肯定不是完全有效。您试图在注释添加到地图之前(因此,在创建此注释的注释视图之前)设置注释视图的
图像。充其量,您正在为之前的注释设置注释视图
图像
,而不是您认为的注释

如果各种批注需要具有唯一的图像,请继续向批注添加
imageName
属性,然后可以让
viewForAnnotation
使用该属性设置批注视图的图像。您应该在这里为注释视图创建
UIImage
。坦率地说,我建议您删除
annView
ivar,以避免尝试在
viewForAnnotation
之外访问注释视图的诱惑


顺便说一句,
MapViewAnnotation
类(在别处称为
MyAnnotation
)本身有很多小问题(例如,您的
init
没有调用
super
,您已经将字符串定义为
copy
参数,但是
init
没有这样做(例如
title=[ttl copy]
),现在建议您不要显式创建支持属性的IVAR等),但这些与注释视图图像的更广泛问题无关。

不要将
annView.image
设置在viewForAnnotation方法之外。在代理方法中设置它,同时设置附件视图。如果它在iOS 6中“起作用”,那只是偶然的。
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapViewAnnotation : NSObject <MKAnnotation> {

    NSString *title;
    CLLocationCoordinate2D coordinate;

}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;

@end

    #import "MapViewAnnotation.h"

@implementation MapViewAnnotation

@synthesize title, coordinate;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {

    title = ttl;
    coordinate = c2d;
    return self;
}


@end