MKAnnotation 未声明
我知道之前有人问过这个问题。然而,我认为有点菜鸟,因为我无法解决它。
我在尝试此操作时遇到该错误:
MKAnnotation *annotation = [[MKAnnotation alloc] initWithCoordinate:coordenada title:@"HELLO!"];
[mapa addAnnotation:annotation];
我也有以下方法:
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation
{
MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapa dequeueReusableAnnotationViewWithIdentifier: @"asdf"];
if (pin == nil)
{
pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"asdf"] autorelease];
}
else
{
pin.annotation = annotation;
}
pin.pinColor = MKPinAnnotationColorRed;
pin.animatesDrop = YES;
return pin;
}
并且执行了 #import <标头中的 MapKit/MKAnnotation.h>
。
有什么帮助吗?
非常感谢!
I know there was a question about this before. However, I think a little bit noob because I can't get it solved.
I'm getting that error when trying this:
MKAnnotation *annotation = [[MKAnnotation alloc] initWithCoordinate:coordenada title:@"HELLO!"];
[mapa addAnnotation:annotation];
I also have the following method:
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation
{
MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapa dequeueReusableAnnotationViewWithIdentifier: @"asdf"];
if (pin == nil)
{
pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"asdf"] autorelease];
}
else
{
pin.annotation = annotation;
}
pin.pinColor = MKPinAnnotationColorRed;
pin.animatesDrop = YES;
return pin;
}
And did the #import < MapKit/MKAnnotation.h>
in header.
Any help please?
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MKAnnotation
是一个协议,而不是一个可以实例化的类。您是否定义了自己的实现
MKAnnotation
和initWithCooperative:title:
方法的类?如果有,请使用该类名并导入其头文件。如果您还没有创建自己的注释类,则必须创建一个,或者可以使用预定义的
MKPointAnnotation
类(在 iOS 4+ 中):您还需要执行 以下操作:以下内容:
#import
delegate
属性(或 IB 中的outlet) )否则地图视图viewForAnnotation
不会被调用MKAnnotation
is a protocol, not a class that you can instantiate.Have you defined your own class that implements
MKAnnotation
and ainitWithCoordinate:title:
method? If you have, use that class name and import its header file.If you haven't created your own annotation class, you'll have to create one or you can use the pre-defined
MKPointAnnotation
class (in iOS 4+) instead:You'll also need to do the following:
#import <MapKit/MapKit.h>
at the top of the filedelegate
property (or outlet in IB) of the map view otherwiseviewForAnnotation
won't get called