3

在我的应用程序中使用地图视图时,有时 MKMapKit 委托方法“mapView:regionDidChange”不调用。它仅在我拖动地图时发生。但是当我放大或缩小时它工作得很好。因此,它会在拖动地图时创建与在地图上放置新注释相关的问题。我已经在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]; 

*/

我检查了所有条件和布尔值,但我的编码不是这个错误的原因。所以可能是它与地区有关,确实改变了方法。

因此,在将我的应用程序与地图一起使用时,20% 的时间它的行为类似于 Ideal(方法不调用)。

有人可以帮我解决这个问题。

先感谢您。

4

1 回答 1

0

编辑它随机坏了,所以我现在再次调用该函数(撤消我在下面所说的),没有额外的变化......嗯,它有效。我感觉我在抛硬币。

我刚刚发生了这种情况,因为我有一个子类 MKMapView。我不知道您是否将其子类化,但出于某种原因,Apple 的超级功能,例如: -(void) scrollViewDidScroll; 调用 super 但未正确拦截并跳过该调用。

当我删除“覆盖”调用时,这只是对 [super scrollView] 的调用,它开始正常工作。

我不知道为什么苹果的代码会以这种方式被破坏(调用 super 没有相同的效果而不是覆盖它),但请确保您没有将这些子类化:ScrollView functions MKMapView functions... 或者可能使用 WildCard Gesture识别器非常友好地提供了为什么地图视图不响应 touchesBegan/Moved 等的答案:如何拦截 MKMapView 或 UIWebView 对象上的触摸事件?.

如果这没有帮助,请确保您没有其他视图之上的视图,不正确的代表,xibs 被安排和连接,通常的东西。

于 2012-09-24T22:13:15.760 回答