ios - iOS上的MapView错误

标签 ios objective-c

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

相关文章:

ios - 动画背景颜色变化 - 一侧到另一侧

iphone - 检查 tabBar 在 iOS 应用程序上是否可见

ios - 在 View Controller 之间传递数据

objective-c - 为什么 NSSet/NSMutableSet/NSCountedSet 不强制不可变对象(immutable对象)作为条目?

objective-c - 如果用户取消首选项面板,则重置 NSUserDefaults

iphone - 在 iOS 5 应用程序中有条件地支持 iOS 6 功能

ios - 来自NSLog的Segfault?

ios - Alamofire - 错误的请求

iphone - 如何替换当前打开的 FMDB 数据库并保留当前队列?

iphone - UIScrollView 委托(delegate)方法冲突