Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c didAddAnnotationViews不在MKMapView上工作_Objective C_Ios_Mkmapview_Mkannotation - Fatal编程技术网

Objective c didAddAnnotationViews不在MKMapView上工作

Objective c didAddAnnotationViews不在MKMapView上工作,objective-c,ios,mkmapview,mkannotation,Objective C,Ios,Mkmapview,Mkannotation,我一直在玩MKMapView,试图了解MKMapViewDelegate系统是如何工作的。到目前为止,我还没有在添加当前位置标记时调用DidAddAnnotationView的运气 我已将我的app delegate设置为实现MKMapViewDelegate,在我的xib中有一个指向MapView的出口,并已将MapView的delegate属性设置为self,如app delegate实例中所示。我在app委托中实现了didAddAnnotationViews,我只需记录对它的任何调用,如下

我一直在玩MKMapView,试图了解MKMapViewDelegate系统是如何工作的。到目前为止,我还没有在添加当前位置标记时调用DidAddAnnotationView的运气

我已将我的app delegate设置为实现MKMapViewDelegate,在我的xib中有一个指向MapView的出口,并已将MapView的delegate属性设置为self,如app delegate实例中所示。我在app委托中实现了didAddAnnotationViews,我只需记录对它的任何调用,如下所示。地图设置为显示当前位置,并在启动时添加蓝针注释,但由于某些原因,未命中didAddAnnotationViews

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
    NSLog(@"Annotation added!");
}

任何我可能错过的想法?

mapView:didAddAnnotations:
仅在响应
addAnnotations:
addAnnotations:
时调用。用户位置pin不会触发此委托方法。

我在BNR中遇到了相同的问题。以下是我最终使用的:

    // Tell MKMapView to zoom to current location when found
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"didUpdateUserLocation just got called!");

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
    [mapView setRegion:region animated:YES];
}

我只是想确认一下,我可以用

 - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id <MKAnnotation> mp = [annotationView annotation];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 250,250);
    [mv setRegion:region animated:YES];
}
-(void)地图视图:(MKMapView*)mv didaddannotationview:(NSArray*)视图
{
MKAnnotationView*annotationView=[views objectAtIndex:0];
id mp=[annotationView注释];
mkcoordinaereregion=mkcoordinaereregionmakewithdistance([mp坐标],250250);
[mv setRegion:区域动画:是];
}
确保您正在使用 mapView.delegate=self; 或
[mapView setDelegate:self]

谢谢,你确定吗?我确实想知道是否是这样,但我一直在关注Big Nerd Ranch关于iPhone编程的书中的Wheremi教程,它非常清楚地指出,添加蓝点表示当前位置时,将调用DidAddAnnotationView。事实上,它提供了一段代码,用于在didAddAnnotationsView中设置当前区域以缩放当前位置。对于作者来说,这似乎是一个巨大的错误。事实上,一点谷歌搜索已经证实了你是对的,苹果改变了IOS 4.0中的行为!显然,我现在需要使用didUpdateUserLocation。