我在Xcode上使用MapView,一切正常,但是当我添加以下行
时mapView.delegate = self;
到ViewController.m,我收到错误
分配给'id< MKMapViewDelegate>'来自不兼容的类型'ViewController * const __strong'
这是我的代码:
ViewController.m:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.showsUserLocation = YES;
mapView.delegate = self; //The line I added that creates the error
// Do any additional setup after loading the view, typically from a nib.
}
@end
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController {
MKMapView *mapview;
}
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end
答案 0 :(得分:2)
您需要声明您的类实现了MKMapViewDelegate方法。在ViewController.h头文件中,更改行
@interface ViewController : UIViewController {
到
@interface ViewController : UIViewController <MKMapViewDelegate> {
答案 1 :(得分:1)
您需要声明自己回复MKMapViewDelegate
来电。
要执行此操作,只需更新相应类(您的示例中为ViewController.h
)的头文件,如下所示:
@interface ViewController : UIViewController <MKMapViewDelegate> {