iOS上的MapView错误

时间:2013-08-25 14:27:17

标签: ios objective-c

我在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

2 个答案:

答案 0 :(得分:2)

您需要声明您的类实现了MKMapViewDelegate方法。在ViewController.h头文件中,更改行

@interface ViewController : UIViewController {

@interface ViewController : UIViewController <MKMapViewDelegate> {

答案 1 :(得分:1)

您需要声明自己回复MKMapViewDelegate来电。

要执行此操作,只需更新相应类(您的示例中为ViewController.h)的头文件,如下所示:

@interface ViewController : UIViewController <MKMapViewDelegate> {