我打电话给Web服务,该服务返回一个代理方法中的注释数组,该方法将使用addAnnotations
方法添加到我的地图中,作为MKMapView
。一切顺利顺顺当当,直到委托方法发送快速连续两个数组(通常约150毫秒 - 500毫秒),然后我得到的这条线[kMap addAnnotations:tileArray];
一个EXC_BAD_ACCESS (code=1 address 0x20)
- 这似乎是一个记忆的问题,但我真的不知道该怎么做如何或如何改变我的代码来解决它。EXC_BAD_ACCESS在MKMapView中添加注释
这里是委托方法
-(void)rebelBaseManager:(RebelBaseManager *)manager didUpdateTileHour:(NSArray *)tileArray boundaryBreak:(NSString *)breakType atTileLevel:(int)callTileLevel {
if (timerStarted == NO) {
[self startTimer];
}
//Check for tileLevel in case multiple calls were made at different tile levels
if (tileLevel == callTileLevel) {
[kMap addAnnotations:tileArray];
[HourInMap addObjectsFromArray:tileArray];
}
}
我还添加了一个方法,让我的动画去除注释这是在以下情况下,它的确与众不同:
- (void)removeAnnotationsWithFade:(NSArray *)annotations animated:(BOOL)shouldAnimate {
if (!shouldAnimate)
[self removeAnnotations:annotations];
else {
for (HourAnnotation *annotation in annotations) {
MKAnnotationView *annotationView = [self viewForAnnotation:annotation];
[UIView animateWithDuration:2
animations:^{
annotationView.alpha =0;
}completion:^(BOOL finished) {
[self removeAnnotation:annotation];
}];
}
}
--- ------ ADDITION ---------
在我的代码中添加一个自定义的回复下面Rob的回答#3中的符号。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithHourAnnotation:(HourAnnotation *)hourAnnotation reuseIdentifier:(NSString *)reuseIdentifier {
CGRect myFrame = self.frame;
myFrame.size.width = hourAnnotation.frameSize;
myFrame.size.height = hourAnnotation.frameSize;
self = [super initWithFrame:myFrame];
//When I use this here I seem to get the frame and color of the old annotation displayed
//self = [super initWithAnnotation:velocityAnnotation reuseIdentifier:reuseIdentifier];
if (self)
{
self.layer.cornerRadius = self.frame.size.width/2;
self.clipsToBounds = YES;
[self setBackgroundColor:[UIColor clearColor]];
NSArray *alphaValue = [[NSArray alloc]initWithArray:[self alphaForTileLevel]];
self.fillColor = [UIColor colorWithHue:hourAnnotation.color saturation:.06 brightness:.23 alpha:[[alphaValue objectAtIndex:hourAnnotation.tileLevel-1]doubleValue]];
self.strokeColor = [UIColor colorWithHue:hourAnnotation.color saturation:.06 brightness:.23 alpha:.35];
self.enabled = NO;
self.canShowCallout = NO;
self.userInteractionEnabled = NO;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect];
[self.fillColor set];
[path fill];
[self.strokeColor set];
[path setLineWidth:2.0f];
[path stroke];
}
可能下面的副本,虽然不完全清楚:http://stackoverflow.com/questions/4202510/mkmapview-crashing-with-exc-bad-access – Rob 2014-08-28 12:56:13
@Rob这个答案的问题,你参考(http://stackoverflow.com/a/8932791/2939977)没有帮助,因为我得到了一些无效的坐标,但我也看到你在下面你的答案解决的几个内存泄漏。我正在研究那些现在的 – 2014-08-28 20:43:31
'kMap'定义在哪里? – jlehr 2014-08-28 21:23:15