在我的项目中,我有一个向其添加注释的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

关于ios - 将UIMapView委托(delegate)设置为self会触发警告,但可以,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24472466/

10-12 12:33
查看更多