문제

나는 이것을 사용할 때마다 "myAnnotation이 mkannotation 프로토콜을 구현하지 않는다"는 경고가 있습니다.


[mapView addAnnotation:annotation];

or

[mapView removeAnnotation:mapView.annotations];

누군가 아이디어가 있습니까?

도움이 되었습니까?

해결책

(주석 개체가 myAnnotation 클래스의 인스턴스라고 가정합니다)

mkmapview는 주석 개체가 준수해야합니다 MKAnnotation 필요한 특정 방법을 구현하기위한 프로토콜 - 그렇지 않으면 응용 프로그램이 런타임에 오류를 생성 할 수 있습니다. 이 프로토콜은 다음과 같이 정의됩니다.

// MKAnnotation.h
@protocol MKAnnotation <NSObject>

// Center latitude and longitude of the annotion view.
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@optional

// Title and subtitle for use by selection UI.
- (NSString *)title;
- (NSString *)subtitle;

@end

이것이 귀하의 myAnnotation 클래스는 정의하고 구현해야합니다 coordinate 속성 및 2 옵션도 구현할 수도 있습니다 title 행동 양식. 컴파일러에게 클래스가 실제로 프로토콜을 준수한다는 것을 알리려면 다음과 같은 방법으로 클래스를 선언해야합니다.

@interface MyAnnotation: NSObject <MKAnnotation> // Or whatever parent class you have
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top