0

尝试为 a 添加一些注释MapView,但不断遇到 ARC 语义问题:'没有可见的 @interface for 'MKPointAnnotation' 声明了选择器 initWithTitle:andCoordinate:

我对此很陌生,所以真的不知道这意味着什么,如果有人能解释/纠正它,我将不胜感激。

这是我的viewDidLoad方法:

- (void)viewDidLoad
{
    CLLocationCoordinate2D location;
    location.latitude = (double) 51.501468;
    location.longitude = (double) -0.141596;

    MKPointAnnotation *newAnnotation = [[MKPointAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
    [self._mapView addAnnotation:newAnnotation];

}

和我的头文件:

#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
4

2 回答 2

3

您创建的 initWithTitle:andCoordinate 方法是 MapViewAnnotation 的方法,而不是 MKPointAnnotation。

你可能想要:

MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
[self._mapView addAnnotation:newAnnotation];
于 2012-12-07T17:38:50.713 回答
0

它试图告诉你它找不到任何与 initWithTitle:andCoordinate 的签名匹配的方法:

MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:coordinate];
[annotation setTitle:@"Buckingham Palace"];
于 2012-12-07T17:30:11.780 回答