Ios EXC_坏_访问图
我正在绘制图形,为此我使用Ios EXC_坏_访问图,ios,objective-c,exc-bad-access,Ios,Objective C,Exc Bad Access,我正在绘制图形,为此我使用SHLineGraphView现在在绘制一个图形之后,我需要删除该图形并再次拖动。一致 CGPathMoveToPoint(backgroundPath, NULL, _leftMarginToLeave, plot.xPoints[0].y); 我收到了一条信息,内容是获取EXC\u BAD\u ACCESS。 这是我的职责。我在我的方案中添加了“是” - (void)drawPlot:(SHPlot *)plot { NSDictionary *theme =
SHLineGraphView
现在在绘制一个图形之后,我需要删除该图形并再次拖动。一致
CGPathMoveToPoint(backgroundPath, NULL, _leftMarginToLeave, plot.xPoints[0].y);
我收到了一条信息,内容是获取EXC\u BAD\u ACCESS
。
这是我的职责。我在我的方案中添加了“是”
- (void)drawPlot:(SHPlot *)plot {
NSDictionary *theme = plot.plotThemeAttributes;
CAShapeLayer *backgroundLayer = [CAShapeLayer layer];
backgroundLayer.frame = self.bounds;
backgroundLayer.fillColor = ((UIColor *)theme[kPlotFillColorKey]).CGColor;
backgroundLayer.backgroundColor = [UIColor clearColor].CGColor;
[backgroundLayer setStrokeColor:[UIColor clearColor].CGColor];
[backgroundLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef backgroundPath = CGPathCreateMutable();
CAShapeLayer *circleLayer = [CAShapeLayer layer];
UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 75, 75)];
circleLayer.path = circle.CGPath;
circleLayer.strokeColor = [UIColor orangeColor].CGColor;
circleLayer.fillColor = [UIColor whiteColor].CGColor;
circleLayer.shadowColor =[UIColor blackColor].CGColor;
circleLayer.lineWidth = 3.0;
[self.layer addSublayer:circleLayer];
CGMutablePathRef circlePath = CGPathCreateMutable();
CAShapeLayer *graphLayer = [CAShapeLayer layer];
graphLayer.frame = self.bounds;
graphLayer.fillColor = [UIColor clearColor].CGColor;
graphLayer.backgroundColor = [UIColor clearColor].CGColor;
[graphLayer setStrokeColor:((UIColor *)theme[kPlotStrokeColorKey]).CGColor];
[graphLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef graphPath = CGPathCreateMutable();
double yRange = [_yAxisRange doubleValue];
double yIntervalValue = yRange / INTERVAL_COUNT;
[plot.plottingValues enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSDictionary *dic = (NSDictionary *)obj;
__block NSNumber *_key = nil;
__block NSNumber *_value = nil;
[dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
_key = (NSNumber *)key;
_value = (NSNumber *)obj;
}];
int xIndex = [self getIndexForValue:_key forPlot:plot];
double height = self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE;
double y = height - ((height / ([_yAxisRange doubleValue] + yIntervalValue)) * [_value doubleValue]);
(plot.xPoints[xIndex]).x = ceil((plot.xPoints[xIndex]).x);
(plot.xPoints[xIndex]).y = ceil(y);
}];
CGPathMoveToPoint(graphPath, NULL, _leftMarginToLeave, plot.xPoints[0].y);
CGPathMoveToPoint(backgroundPath, NULL, _leftMarginToLeave, plot.xPoints[0].y);
int count = _xAxisValues.count;
for(int i=0; i< count; i++){
CGPoint point = plot.xPoints[i];
CGPathAddLineToPoint(graphPath, NULL, point.x, point.y);
CGPathAddLineToPoint(backgroundPath, NULL, point.x, point.y);
CGPathAddEllipseInRect(circlePath, NULL, CGRectMake(point.x - 5, point.y - 5, 10, 10));
}
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave + PLOT_WIDTH, self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE);
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave, self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE);
CGPathCloseSubpath(backgroundPath);
backgroundLayer.path = backgroundPath;
graphLayer.path = graphPath;
circleLayer.path = circlePath;
CGPathRelease(backgroundPath);
CGPathRelease(circlePath);
CGPathRelease(graphPath);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = 1;
animation.fromValue = @(0.0);
animation.toValue = @(1.0);
[graphLayer addAnimation:animation forKey:@"strokeEnd"];
backgroundLayer.zPosition = 0;
graphLayer.zPosition = 1;
circleLayer.zPosition = 2;
[self.layer addSublayer:graphLayer];
[self.layer addSublayer:circleLayer];
[self.layer addSublayer:backgroundLayer];
NSUInteger count2 = _xAxisValues.count;
for(int i=0; i< count2; i++){
CGPoint point = plot.xPoints[i];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor clearColor];
btn.tag = i;
btn.frame = CGRectMake(point.x - 10, point.y - 10, 40, 40);
[btn addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
objc_setAssociatedObject(btn, kAssociatedPlotObject, plot, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self addSubview:btn];
}
-(无效)绘图:(SHPlot*)绘图{
NSDictionary*theme=plot.plotThemeAttributes;
CAShapeLayer*backgroundLayer=[CAShapeLayer层];
backgroundLayer.frame=self.bounds;
backgroundLayer.fillColor=((UIColor*)主题[kPlotFillColorKey]).CGColor;
backgroundLayer.backgroundColor=[UIColor clearColor].CGColor;
[backgroundLayer setStrokeColor:[UIColor clearColor].CGColor];
[backgroundLayer setLineWidth:((NSNumber*)主题[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef backgroundPath=CGPathCreateMutable();
CAShapeLayer*circleLayer=[CAShapeLayer层];
UIBezierPath*circle=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0,75,75)];
circleLayer.path=circle.CGPath;
circleLayer.strokeColor=[UIColor orangeColor].CGColor;
circleLayer.fillColor=[UIColor whiteColor].CGColor;
circleLayer.shadowColor=[UIColor blackColor].CGColor;
circleLayer.lineWidth=3.0;
[self.layer addSublayer:circleLayer];
CGMutablePathRef circlePath=CGPathCreateMutable();
CAShapeLayer*graphLayer=[CAShapeLayer层];
graphLayer.frame=self.bounds;
graphLayer.fillColor=[UIColor clearColor].CGColor;
graphLayer.backgroundColor=[UIColor clearColor].CGColor;
[graphLayer setStrokeColor:((UIColor*)主题[kPlotStrokeColorKey]).CGColor];
[graphLayer setLineWidth:((NSNumber*)主题[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef graphPath=CGPathCreateMutable();
双Y范围=[[u yAxisRange doubleValue];
双yIntervalValue=Y范围/间隔计数;
[plot.plottingValues enumerateObjectsUsingBlock:^(id obj,整数idx,布尔*停止){
NSDictionary*dic=(NSDictionary*)obj;
__块NSNumber*_key=nil;
__块NSNumber*_值=零;
[dic enumerateKeysAndObjectsUsingBlock:^(id键、id对象、布尔*停止){
_键=(NSNumber*)键;
_值=(NSNumber*)obj;
}];
int xIndex=[self getIndexForValue:_-key for-plot:plot];
双倍高度=self.bounds.size.height-底部至左边的边距;
双y=高度-((高度/([[u yAxisRange doubleValue]+yIntervalValue))*[[u value doubleValue]);
(plot.xPoints[xIndex]).x=ceil((plot.xPoints[xIndex]).x);
(plot.xPoints[xIndex]).y=ceil(y);
}];
CGPathMoveToPoint(graphPath,NULL,_leftMarginToLeave,plot.xPoints[0].y);
CGPathMoveToPoint(backgroundPath,NULL,_leftMarginToLeave,plot.xPoints[0].y);
int count=\u xAxisValues.count;
for(int i=0;i
}
感谢使用NSZombie找出错误。检查所有值是否为“零”。检查plot.xPoints[]是否包含任何内容。Yes plot.xPoints[]包含数据。如@Rushabh所述,在此处共享崩溃日志-启用NSZombie查找错误/异常/日志。