[MKAnnotation]警告:在协议中找不到\'-setTitle:\'

| 我有一个名为
MyAnnotation
的子类来管理注释协议,我的问题是在构建应用程序时,它给了我这个警告:
\'-setTitle:\' not found in protocol(s)   
编译器将我指向引起警告的这一行:
annView.annotation.title = @\"You are here\";
其中
annView
MKPinAnnotationView
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@\"currentLoc\"];
您能帮我解决该警告吗?提前谢谢:)
已邀请:
MKPinAnnotationView
annotation
属性(是
MKAnnotationView
的子类)的类型为
id<MKAnnotation>
,它没有定义
-setTitle:
方法。 但是,如果实现
MKAnnotation
协议的类为其自身定义了
-setTitle:
方法(例如,使用
@property
声明),则可以如下设置标题:
MyAnnotationClass *myAnnot = (MyAnnotationClass *)annView.annotation;
myAnnot.title = @\"You are here\";
但是,您可能应该在创建注释时和在调用
addAnnotation
之前设置注释的标题,而不是在
viewForAnnotation
中进行设置。 同样,给班级命名为
MkAnnotation
也不是一个好主意。它很容易与ѭ11协议混淆。改用
MalekAnnotation
之类的东西。

要回复问题请先登录注册