[英]Setting UIMapView delegate to self triggers warning, but works
In my project, I have a MapView that I add annotations to. 在我的项目中,我有一个向其添加注释的MapView。 I need those annotations to have different images, so I use the - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
method. 我需要这些注释具有不同的图像,因此我使用- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
方法。 However, for this to work I need the MapView's delegate to be set to self
. 但是,要使其正常工作,我需要将MapView的委托设置为self
。 So I use this line in the viewDidLoad
function: 因此,我在viewDidLoad
函数中使用了这一行:
self.viewMap.delegate = self;
This works as expected, however XCode is warning me with this message: 这可以按预期工作,但是XCode通过以下消息警告我:
Assigning to 'id<MKMapViewDelegate>' from incompatible type 'ViewController *const__strong'
I'm guessing that I am not going about this the proper way, and that's why there's a warning. 我猜我没有按照正确的方式进行操作,这就是为什么会有警告的原因。 So what am I doing wrong? 那我在做什么错?
Your ViewController
class—which you might consider renaming to something more descriptive—needs to declare conformance to MKMapViewDelegate
in its interface: 您的ViewController
类(您可能会考虑重命名为更具描述性的类)需要在其接口中声明对MKMapViewDelegate
符合性:
@interface ViewController : UIViewController <MKMapViewDelegate>
// stuff
@end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.