In a UIViewController I add a MKMapView to the view controlled by the controller.
- (void)viewDidLoad {
[super viewDidLoad];
CGRect rect = CGRectMake(0, 0, 460, 320);
map = [[MKMapView alloc] initWithFrame:rect];
map.delegate = self;
[self.view addSubview:map];
}
Later in the controller I have
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
NSLog(@"done.");
}
Done never gets printed. None of the other delegate methods get called either like mapView:viewForAnnotation: I use a MKMapView in an another app, but this seems to happen on any new application I make. Has anyone else seen this behavior?
EDIT:
The problem seems to be when UIViewController is made the delegate of the MKMapView, a direct subclass of NSObject seems to work okay. I can work around like this, still seems very odd since I've done it before.
I had a similar issue in XCode 6.1 building for iOS 8.1 where none of the MKMapViewDelegate methods were being called. In a 2nd application the identical code resulted in the MKMapViewDelegate methods being called as expected.
In ViewController.m the mapView delegate was set as follows:
- (void)viewDidLoad {
...
self.mapView.delegate = self;
In ViewController.h:
@interface myMapViewController : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@end
I had manually added the IBOutlet line above to the header file, but only in the app where the delegate methods were not being received.
The solution was to delete the IBOutlet line I had added manually to the header, and then go to the storyboard and CTRL-drag from the MKMapView to the @interface block in my ViewController.h. The identical IBOutlet was recreated in the header file with the result that all the delegate methods were called correctly.
A bit old, but since iOS 7 there is a new method that might work. solved my problem
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered
I had the exact same problem: I had assigned < MKMapViewDeledate> to my controller, and linked the delegate to "File owner" in Interface Builder, but still my implemented delegate methods were not called.
The reason is that since iOS 4, maps are cached, and whenever an app display a cached map then methods such as "mapViewDidFinishLoadingMap" are not called. Resetting "contents and settings" in the simulator clears the cached maps and therefore solves the issue.
Perhaps you need to go to the IB and control-drag from the MKMapView to the view conroller, then select delegate to make it a delegate???
maybe quite obvious, but just checking:
Have you made sure your viewcontroller declaration is correctly done. Something like:
@interface YourViewController : UIViewController <MKMapViewDelegate>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With