我在Xcode上使用MapView,并且一切正常,但是当我添加以下行时
mapView.delegate = self;
到ViewController.m,我得到了错误
从不兼容的类型'ViewController * const分配给'id
__强大'
这是我的代码:
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
最佳答案
您需要声明您的类实现了MKMapViewDelegate方法。在您的ViewController.h头文件中,更改行
@interface ViewController : UIViewController {
至
@interface ViewController : UIViewController <MKMapViewDelegate> {
关于ios - iOS上的MapView错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18430014/