Ios MKMapView';不调用s的委托

Ios MKMapView';不调用s的委托,ios,delegates,mkmapview,mkannotation,mkmapviewdelegate,Ios,Delegates,Mkmapview,Mkannotation,Mkmapviewdelegate,我有一个UIViewController类来管理MKMapView定义如下: @interface MapViewController : UIViewController <MKMapViewDelegate> @接口MapViewController:UIViewController 在该视图控制器的实现中,我有: - (void)loadView { MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRec

我有一个
UIViewController
类来管理
MKMapView
定义如下:

@interface MapViewController : UIViewController <MKMapViewDelegate>
@接口MapViewController:UIViewController
在该视图控制器的实现中,我有:

- (void)loadView
{
   MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
   mapView.delegate = self;
   self.view = mapView;
}


- (void)centerMapInLoc:(CLLocation *)loc
{
   CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithCoordinates:loc.coordinate title:@"My position" subTitle:nil];

   [(MKMapView *)self.view addAnnotation:annotation];
}


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
   MKAnnotationView *v = nil;

   // Custom logic

   v.annotation = annotation;
   return v;
}
-(无效)加载视图
{
MKMapView*mapView=[[MKMapView alloc]initWithFrame:CGRectMake(0,0300200)];
mapView.delegate=self;
self.view=mapView;
}
-(无效)centerMapInLoc:(CLLocation*)loc
{
CustomAnnotation*annotation=[[CustomAnnotation alloc]initWithCoordinates:loc.coordinate title:@“我的位置”副标题:nil];
[(MKMapView*)self.view addAnnotation:annotation];
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
MKAnnotationView*v=nil;
//自定义逻辑
v、 注释=注释;
返回v;
}
是从另一个视图控制器调用的公共方法。注释是在这样的方法中创建的,但是添加注释时不会调用
viewForAnnotation:
delegate方法。我不明白为什么,因为委托是在
loadView
方法中设置的


提前感谢

您是否在地图中查看注释的坐标??,
viewForAnnotation
仅当注释将出现在地图上时才会执行。移动到地图中应显示注释的部分,并验证是否正在使用该方法called@gabuh是的,我正在显示适当的区域,事实上,如果我在
viewDidLoad
方法中添加注释,调用了
viewForAnnotation
delegate方法并显示批注…您确定从另一个viewController调用centerMapInLoc时已初始化self.view吗?centerMapInLoc中的NSLog self.view。@gabuh是的,它是。。。委托似乎也不同于nil…尝试将mapView作为主视图的子视图添加到viewController中,而不是替换它<代码>[self.view addSubview:mapView]您可以在viewController中保留对mapView的引用(添加MKMapView属性),以帮助您在centerMapInLoc中添加注释