viewForOverlay 从未被调用

发布于 2024-12-05 03:29:24 字数 1326 浏览 2 评论 0原文

我可以查看分段的按钮。单击索引为“1”的按钮时,它应该显示带有一些叠加层的地图视图。因此,我有以下代码:

    {
        [_routeMap setHidden:NO];
        [self drawTheMap];
        [_routeMap setRegion:_region animated:YES];
        [_routeMap regionThatFits:_region];
        [_navBar setHidden:NO];
        NSLog(@"overlays: %@", _routeMap.overlays);
    }
    -(void)drawTheMap
    {
        [_routeMap setFrame:CGRectMake(0, 44, 320, 416)];
        for (int i=0; i<[_arrayOfPoints count]; i++) {
            CLLocation* location = [[CLLocation alloc] initWithLatitude:[[_arrayOfPoints objectAtIndex:i] latitude] 
                                                          longitude:[[_arrayOfPoints objectAtIndex:i] longitude]];

    ... 
        MKCircle * dot = [MKCircle circleWithCenterCoordinate:location.coordinate radius:radius];
            [_routeMap addOverlay:dot];

    ...  
    }
    ...
    }
    - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKCircleView *circleView = [[MKCircleView alloc] initWithCircle:overlay];
    circleView.lineWidth = 1.0;
    circleView.strokeColor = [UIColor orangeColor];
    [circleView setFillColor:[UIColor orangeColor]];

    return [circleView autorelease];
}

但 viewForOverlay 方法永远不会被调用=(。 NSLog 向我显示 mkmapview 包含一些叠加层。 有人可以帮助我吗?

I have view with segment's buttons. on clicking on button with index "1", it should show mapview with some overlays. For this reason, I have the following code:

    {
        [_routeMap setHidden:NO];
        [self drawTheMap];
        [_routeMap setRegion:_region animated:YES];
        [_routeMap regionThatFits:_region];
        [_navBar setHidden:NO];
        NSLog(@"overlays: %@", _routeMap.overlays);
    }
    -(void)drawTheMap
    {
        [_routeMap setFrame:CGRectMake(0, 44, 320, 416)];
        for (int i=0; i<[_arrayOfPoints count]; i++) {
            CLLocation* location = [[CLLocation alloc] initWithLatitude:[[_arrayOfPoints objectAtIndex:i] latitude] 
                                                          longitude:[[_arrayOfPoints objectAtIndex:i] longitude]];

    ... 
        MKCircle * dot = [MKCircle circleWithCenterCoordinate:location.coordinate radius:radius];
            [_routeMap addOverlay:dot];

    ...  
    }
    ...
    }
    - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKCircleView *circleView = [[MKCircleView alloc] initWithCircle:overlay];
    circleView.lineWidth = 1.0;
    circleView.strokeColor = [UIColor orangeColor];
    [circleView setFillColor:[UIColor orangeColor]];

    return [circleView autorelease];
}

but the viewForOverlay method is never called =(.
NSLog shows me that mkmapview contain some overlays.
Can anybody help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最佳男配角 2024-12-12 03:29:24

在方法 -(void)drawTheMap 中,而不是 [_routeMap addOverlay:dot]; 尝试 [self addOverlay:dot];

In the method -(void)drawTheMap , instead of [_routeMap addOverlay:dot]; try [self addOverlay:dot];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文