0

正如标题所说的方法

- (MKAnnotationView *)mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>)annotation {

被调用,mapView1和注解都是nil

我在 viewDidAppear 方法中以通常的方式添加一个注释:

    [mapView addAnnotation:_a];

尝试了两种注释实现——自定义和标准。这是标准注释使用:

MKPointAnnotation *_aa=[[MKPointAnnotation alloc]init];
CLLocationCoordinate2D coordinates;
coordinates.latitude=39.281520;
coordinates.longitude= -76.580806;
_aa.coordinate= coordinates;
_aa.title=@"annotation 2";

[mapView addAnnotation:_aa];
4

2 回答 2

0

MapAnnotation.h

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

        @interface MapAnnotation : NSObject <MKAnnotation>
        @property(nonatomic, assign)    CLLocationCoordinate2D coordinate;
        @property(nonatomic, copy)      NSString *title;
        @property(nonatomic, copy)      NSString *subtitle;

    -(id)initWithCoordinate:(CLLocationCoordinate2D)Region withtitle:(NSString *)Title andSubTitle:(NSString *)SubTitle ;

MapAnnotation.m

@implementation EventAtPlacesAnnotation
@synthesize title = _title, subtitle = _subtitle,coordinate = _coordinate;

 -(id)initWithCoordinate:(CLLocationCoordinate2D)Region withtitle:(NSString *)Title andSubTitle:(NSString *)SubTitle 
{

    self = [super init];
    if(self){
        _title = Title;
        _subtitle = SubTitle;
        _coordinate = Region;
    }
    return self;
}

从您使用地图视图的类中分配值

    CLLocationCoordinate2D newCoordinate = CLLocationCoordinate2DMake(40.56, 90.83);

    MapAnnotation *firstannotation = [[MapAnnotation alloc]initWithCoordinate:newCoordinate withtitle:@"Place 1" andSubTitle:@"Near To empire state"];

[myMapview addAnnotation:firstannotation];
于 2013-04-17T09:32:52.173 回答
0

事实证明,在拖入 UI 构建器时,某些“魔法”被破坏了。重新构建屏幕和控制器,现在一切都像宣传的那样工作。

于 2013-04-17T13:10:57.290 回答