我在 Xcode 上使用 MapView,一切正常,但是当我添加以下行时
mapView.delegate = self;
到 ViewController.m,我得到了错误
从不兼容的类型“ViewController *const __strong”分配给“id<MKMapViewDelegate>”
这是我的代码:
视图控制器.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
视图控制器.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController {
MKMapView *mapview;
}
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end