views:

332

answers:

1

I have a MKMapView inside a UITableView as a custom cell (don't ask ;) - don't know if it matters really), for which I register a regionDidChangeAnimated delegate method. This method gets called three times when the UITableView is loaded - once with the actual region and then two more times with a region that is way off. In the simulator, I consistently get a region with center (+37.43997405, -97.03125000). On the device, it seems to depend on the location reported by the location manager, which initializes the map view.

Why am I getting three regionDidChangeAnimated calls? And why are the center coordinates for the last two of them off?

This is the code I use to get the center coordinates:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    CLLocation *l = [[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude];
(....)
A: 

I have set up a map view inside a custom table view cell and added that cell to a table view (although it definitely should not matter where/how the map view is displayed).

I do not see any unexpected calls to the regionDidChangeAnimated: delegate method.

I see calls to this method only when:

  1. The user changes the position/zoom of the map, OR
  2. Some code changes the center/span of the map

Are you sure that you are seeing unexpected calls? You are not using code to setup the region (center/span) of the map?

gerry3
You're right - it should not matter where the map view is, but as I can't seem to pin down the source of the region change calls, I thought I'd provide some context.I have done some more debugging and will augment the description of the problem with my findings.
mvexel