繁体   English   中英

将UIMapView委托设置为self会触发警告,但可以

[英]Setting UIMapView delegate to self triggers warning, but works

在我的项目中,我有一个向其添加注释的MapView。 我需要这些注释具有不同的图像,因此我使用- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation方法。 但是,要使其正常工作,我需要将MapView的委托设置为self 因此,我在viewDidLoad函数中使用了这一行:

self.viewMap.delegate = self;

这可以按预期工作,但是XCode通过以下消息警告我:

Assigning to 'id<MKMapViewDelegate>' from incompatible type 'ViewController *const__strong'

我猜我没有按照正确的方式进行操作,这就是为什么会有警告的原因。 那我在做什么错?

您的ViewController类(您可能会考虑重命名为更具描述性的类)需要在其接口中声明对MKMapViewDelegate符合性:

@interface ViewController : UIViewController <MKMapViewDelegate>

// stuff

@end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM