不调用MKMapView的委托

时间:2015-01-14 08:50:26

标签: ios delegates mkmapview mkannotation mkmapviewdelegate

我有一个UIViewController课来管理这样定义的MKMapView

@interface MapViewController : UIViewController <MKMapViewDelegate>

在这个视图控制器的实现中,我有:

- (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;
}

centerMapInLoc:作为公共方法,我从另一个视图控制器调用。注释是在此类方法中创建的,但添加注释时不会调用viewForAnnotation:委托方法。我不明白为什么,因为委托是用loadView方法设置的。

提前致谢

0 个答案:

没有答案
相关问题