لا ينفذ MyAmnOTation بروتوكول Mkannotation
-
19-09-2019 - |
سؤال
لدي تحذير "MyAiNotation لا ينفذ بروتوكول Mkannotation" في كل مرة أستخدمه هذا:
[mapView addAnnotation:annotation];
or
[mapView removeAnnotation:mapView.annotations];
شخص ما لديه فكرة؟
المحلول
(افترض أنك كائن التوضيحي هو مثال على فئة MyAmanItation)
تتطلب 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
هذا هو فئة myAmanotation يجب أن تحدد وتنفيذ coordinate
الممتلكات وقد تنفذ أيضا 2 اختياري title
طرق. للسماح للمجموع برعاية أن صفك يتوافق بالفعل مع بروتوكول يجب أن تعلن صفك الطريقة التالية:
@interface MyAnnotation: NSObject <MKAnnotation> // Or whatever parent class you have
لا تنتمي إلى StackOverflow