未调用iOS MKMapView viewForOverlay

时间:2015-02-08 08:05:11

标签: ios mkmapview

我在这里失去了理智。为什么这不起作用?调用update_map方法但viewForOverlay不会。

- (void)viewDidLoad {
    [super viewDidLoad];

    if(mapView2 != nil)
    {
        [self update_map];
    }

- (void)update_map
{
    CLLocationDistance fenceDistance = 100000;

    MKCircle *circle = [MKCircle circleWithCenterCoordinate:newCoord radius:fenceDistance];
    [mapView2 addOverlay:circle];
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
    NSLog(@"circle overlay");
    MKCircleView *circleView = [[MKCircleView alloc initWithOverlay:overlay];
    [circleView setFillColor:[UIColor blueColor]];
    [circleView setAlpha:0.1f];
    return circleView;
}

1 个答案:

答案 0 :(得分:0)

确保您的视图控制器支持<RKMapViewDelegate>协议,delegate实例的mapView2属性设置为视图控制器,可以是.xib,也可以通过编程方式设置,如下所示:

- (void)viewDidLoad 
{
   [super viewDidLoad];

   self.mapView2.delegate = self;
}