tags:

views:

1302

answers:

4

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.

A: 

maybe quite obvious, but just checking:

Have you made sure your viewcontroller declaration is correctly done. Something like:

@interface YourViewController : UIViewController <MKMapViewDelegate>
Prakash
Indeed I have. I'm wondering if it has anything to do with the new way XCode 3.2 and the SDK work together. This is the first Mapkit I have tried starting since 10.6 came out.
criscokid
+2  A: 

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???

Yoichi
This is the correct solution. I was the mapview must know who its delegate is.
DexterW
A: 

Hello, I also met same issue as yours. I found that: with the iPhone SDK 3.2 - when I create a new UIViewController with an associated xib file (the checkbox option in UIViewController creating dialog), delegate methods of MKMapViewDelegate are never called.

However, when I follow below steps, it runs well.

  1. Create a new UIViewController class (never check the option: create xib file associated with the controller)

  2. Create a new xib file. Add the map using Interface Builder + setting the Owner class with the class on step 1 + setting delegate object of the map point to the owner class.

  3. Implement delegate methods for the UIViewController class in step 1.

  4. When I want to use my ViewController (with the added map), I load it with the nib name as below example:

    MapPreviewController* mapPreviewController = [[MapPreviewController alloc] initWithNibName:@"MapPreviewController" bundle:[NSBundle mainBundle]]; [self.centerPanelView addSubview:mapPreviewController.view];

The code runs ok. I don't know what Apple changes or did with the xib file when I create my UIViewController using the wizard, but it may the root cause of my problem. It takes me 1 day to find this stupid solution.

If you found another one, please share to me.

Thanks

trandangkhoa
That's kind of hacky... why isn't the delegate being called?
DexterW
A: 

I had a similar problem with the methods of MKMapViewDelegate not being called. My issue was setting the MKCoordinateRegionMakeWithDistance and regionThatFits in the controller's -viewDidLoad() I wanted to only show the region around my house and not start with the world view. So after adding annotations in the controller's viewDidLoad, I started a timer. When it expires in one second, I zoom in on the region I want with the above APIs and the delegate methods fire. It just makes me a little dizzy and inclined to vomit on my iPad.

Now I only have to deal with the darn low memory warnings.

bobh