multiple regionDidChangeAnimated calls - what gives?

泪湿孤枕 提交于 2019-12-13 20:10:49

问题


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];
(....)

回答1:


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?



来源:https://stackoverflow.com/questions/2074129/multiple-regiondidchangeanimated-calls-what-gives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!