Reputation: 1559
I was using MapView on Xcode, and everything was working fine, but when I added the following line
mapView.delegate = self;
to ViewController.m, I get the error
Assigning to 'id<MKMapViewDelegate>' from incompatible type 'ViewController *const __strong'
Here is my code:
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
Upvotes: 1
Views: 701
Reputation: 6030
You need to declare that your class implements the MKMapViewDelegate methods. In your ViewController.h header file, change the line
@interface ViewController : UIViewController {
to
@interface ViewController : UIViewController <MKMapViewDelegate> {
Upvotes: 2
Reputation: 54415
You need to declare that you respond to MKMapViewDelegate
calls.
To do this, simply update the header file for the corresponding class (ViewController.h
in your example) as follows:
@interface ViewController : UIViewController <MKMapViewDelegate> {
Upvotes: 1