【问题标题】:Warning: 'MKMapView' may not respond to '-addCircleWithRadius:'警告:“MKMapView”可能不会响应“-addCircleWithRadius:”
【发布时间】:2011-10-18 14:39:51
【问题描述】:

我测试应用程序的前两到三个边缘,在我使用创建的 UISlider 更改圆的直径(覆盖)后它崩溃了几次,然后它崩溃了。现在,就在我点击/点击时滑块更改值,它突然崩溃。结果我有一个警告'MKMapView'可能无法响应'-addCircleWithRadius:'。我做错了什么?我也在发布代码。

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
    return;

CGPoint touchPoint = [gestureRecognizer locationInView:mapview];    
CLLocationCoordinate2D touchMapCoordinate = [mapview convertPoint:touchPoint toCoordinateFromView:mapview];

//add pin where user touched down...
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = touchMapCoordinate;
pa.title = @"Kerkim me baze rrethin";
[mapview addAnnotation:pa];
[pa release];
tmC = touchMapCoordinate;

double radius = 500.0;

MKCircle *circle = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview addOverlay:circle];

}

- (void)addCircleWithRadius:(double)radius
{
MKCircle *circle = [MKCircle circleWithCenterCoordinate:tmC radius:radius];
[mapview addOverlay:circle];
[circle release];
}

- (IBAction)sliderChanged:(UISlider *)sender
{
[mapview removeOverlays:[mapview overlays]];    
double radius = (sender.value);
[mapview addCircleWithRadius:radius];//Here appears the warning,this is the order of my code.
}

【问题讨论】:

    标签: iphone ios memory-leaks warnings


    【解决方案1】:

    MKMapView 类没有 addCircleWithRadius: 方法 - 该方法是您编写的类的一部分,因此您可能应该调用 [self addCircleWithRadius:radius]

    【讨论】:

    • 是的,并从该方法中删除 [circle release];,因为 circle 将被自动释放。
    • 谢谢!现在问题已经解决了。我也删除了[circle release];。但是,我可以问另一个问题,因为与此代码有关吗?就像在问题MKOverlay not resizing smoothly 中一样,覆盖层根本无法顺利调整大小。有时,当滑块处于较大的值位置时,叠加层甚至会消失。我必须将其置于较低的值,然后再将其置于该位置才能使其可见。它可能是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 2011-01-06
    相关资源
    最近更新 更多