3

while using map view in my application some times MKMapKit delegate method 'mapView: regionDidChange' do not call. Its happens only when I drag the map. but when i zoom in or Zoom out Its working perfectly. So its create issue related to place new annotations on map while dragging the map. I have do this code in mapView:regionDidChange:

int j=0;

-(void) mapView:(MKMapView *)mapsView regionDidChangeAnimated:(BOOL)animated{

    zoomLevel = self.mapView.region.span.latitudeDelta;

    if (![appDelegate internetConnected]){
        return;
    }

    if (appDelegate.isMapViewRegionChanged) {
        if (j==0) {
            j++;
            return;
        }else{
            j=0;
            appDelegate.isMapViewRegionChanged  = FALSE;
            return;
        }
    }
    [self callGetMapViewWithObject:nil];
}


/*
first boolean is to check Internet connection.

[appDelegate internetConnected]

Second condition is to return when we navigate from any view controller too map View controller.

appDelegate.isMapViewRegionChanged

Third is a method to place new annotations. 

[self callGetMapViewWithObject:nil]; 

*/

I checked all conditions and booleans but my coding is not reason for this bug. so may be its related to region did change method.

So while using my app with map, 20% of time its behave like Ideal(method do not call).

can some one help me out with this.

Thank you in advance.

josh3736
  • 139,160
  • 33
  • 216
  • 263
Victor
  • 127
  • 1
  • 8

1 Answers1

0

EDIT It broke randomly, so I now call the function again (undoing what I said below), no changes extra... and um, it works. I feel like I'm flipping a coin.

I just had this happen because I have a subclassed MKMapView. I don't know if you're subclassing this or not, but for some reason Apple's super functions, eg: -(void) scrollViewDidScroll; called super but was not intercepted properly and skipped that call.

When I removed the "overridden" call, that was just a call to [super scrollView], it started working properly.

I don't know why apple's code is broken that way (calling super doesn't have the same effect not overriding it), but make sure you're not subclassing these: ScrollView functions MKMapView functions... or perhaps using the WildCard Gesture Recognizer provided very kindly by the answer to why Map Views don't respond to touchesBegan/Moved etc here: How to intercept touches events on a MKMapView or UIWebView objects? .

If this doesn't help, ensure you don't have a view on top of the other views, improper delegates, xibs are arranged and hooked up, the usual stuff.

Community
  • 1
  • 1
Stephen J
  • 2,367
  • 2
  • 25
  • 31
  • It seems every time I change that line, the code unbreaks for one run in the sim... then is broken after. Doesn't matter which way I change it. Sorry I don't have device specifics on what this will do, anyone? – Stephen J Sep 24 '12 at 23:02