尝试为MapView
添加一些注释,但不断出现ARC语义问题:''MKPointAnnotation'没有可见的@interface'声明选择器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
答案 0 :(得分:3)
您创建的initWithTitle:andCoordinate方法是MapViewAnnotation的方法,而不是MKPointAnnotation。
你可能想要:
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
[self._mapView addAnnotation:newAnnotation];
答案 1 :(得分:0)
它试图告诉你,它找不到与initWithTitle签名匹配的任何方法:andCoordinate:
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:coordinate];
[annotation setTitle:@"Buckingham Palace"];