Search code examples
iosmkmapviewzoomingsegueregion

MKMapView does not change region


I have an app where I have a table and after clicking on a cell, the nav controller segues to a MKMapView. I wanna set the region of the map manually so the user sees a zoomed view over a particular area. To do that, in viewWillAppear i do :

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(53.345305, -6.2721597);
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 3000, 3000);
self.map.region = region;

The thing is, the first time around I segue to a map view, it seems to have no effect what so ever on a map. Its only when I go back to the the table view, and segue to the map again, the MKMapView actually moves to a given co-ord and zooms in. Has anyone ever encountered such strange behaviour?


Solution

  • Could it be that viewWillAppear is too early in the process for the map to be ready? Try moving your code to viewDidAppear and see if that helps.