2

I'm setting my MKMapView region inside the viewWillAppear: so that the map displays the good region right as soon as the user sees it:

[mapView setRegion:region animated:NO];

The fist time I do it, I get the region trimmed like so:

alt text

Then from there on, when I set the exact same region, I get something like this:

alt text

The 2nd screenshot is what I want to get from the start. My guess is the first time I set the region, the mapview isn't fully loaded or something along these lines. Any pointer of what I should do to fix this?

EDIT: This is probably related: adding an annotation to the mapView before a first call to viewDidAppear is made isn't working either. The pinView just doesn't show up. How can I make sure the map view is ready to be used within viewWillAppear?

3 Answers 3

1

Issues have been reported regarding the setRegion method some time ago, I don't know if they've been fixed since then. Take a look at the following post on the Apple Dev Forums:

https://devforums.apple.com/message/57488

1
  • good pointer. That setRegion odd behavior bug might be my issue. But still couldn't find a fix :( Nov 19, 2010 at 15:40
1

I stumbled upong this thread that suggested to add a delay to the setRegion: call (if you require to call it within the viewWillAppear method anyway). Kinda silly, but it works.

- (void)viewWillAppear:(BOOL)animated {
    [self performSelector:@selector(centerMap:) withObject:nil afterDelay:0.01];
}

I'm really curious as of what the mapView is missing to do the proper recentering without this delay.

0

Have you tried making the call from the MKMapViewDelegate mapViewDidFinishLoadingMap message? Perhaps this is late enough to get the region right?

2
  • 1
    putting the call in mapViewDidFinishLoadingMap is equivalent of putting in viewDidAppear (in which it works every time). I want the region to already be set when the view appears to the user. Nov 19, 2010 at 15:26
  • I added my setRegion code to this method but the method isnt being called. I thought it was called automatically?
    – marciokoko
    Dec 12, 2012 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.