我有一个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
方法中设置的。
提前致谢