Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you make your view controller a <code>delegate</code> for the <code>MKMapView</code> and implement <code>regionDidChangeAnimated</code>, you'll see that when you first create a map view, the <code>centerCoordinate</code> is <code>30, -40</code>, but it's subsequently set to <code>37.178181, -96.054581</code> (for U.S. users, at least). You apparently can't rely upon the <code>region</code> and/or <code>centerCoordinate</code> immediately after creating the map view. You have to give it a chance to reset its <code>region</code>, which apparently happens asynchronously. </p> <p>If you want to save the <code>defaultRegion</code> after the <code>MKMapView</code> sets it the first time, set the <code>delegate</code> property of the <code>MKMapView</code> and then implement:</p> <pre><code>- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { static BOOL firstTime = YES; if (firstTime) { defaultRegion = mapView.region; firstTime = NO; } } </code></pre> <p>Note, on <code>viewWillDisappear</code>, since you've made your map a <code>static</code>, make sure to <code>nil</code> the map's <code>delegate</code> (since that old view controller will disappear). If you want to continue to have your new instance of the view controller to be a <code>MKMapViewDelegate</code>, then just set the <code>delegate</code> again when you re-add the map view to your new instance of your detail view controller.</p> <hr> <p>Old answer:</p> <p>When you set <code>defaultRegion</code>, that's an instance variable. Thus, that's lost when you dismiss the view. When you come back to the map (i.e. <code>firstTime</code> is <code>NO</code>), the <code>defaultRegion</code> is never initialized, and thus is 0,0, and thus is in the middle of the Atlantic Ocean.</p> <p>You're obviously not saving the <code>defaultRegion</code> (generally you'd have a protocol to pass that back to the master view controller), which makes it hard for the app to know what to do when you select the item in the master view again.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload