【发布时间】:2017-01-03 16:13:35
【问题描述】:
我试图在一个绘图中叠加多个图表,但我在下面的 CPTScatterPlotDelegate 类 CPTScatterPlot.m 中遇到崩溃(EXC_BAD_ACCESS)
-(void)renderAsVectorInContext:(nonnull CGContextRef)context {
...
// Draw line
if ( theLineStyle ) {
CGPathRef dataLinePath = [self newDataLinePathForViewPoints:viewPoints indexRange:viewIndexRange baselineYValue:CPTNAN];
// Give the delegate a chance to prepare for the drawing.
id<CPTScatterPlotDelegate> theDelegate = self.delegate;
....
}
...
}
CPTPlot.m 类中的 CPTLegendDelegate 相同
-(void)drawSwatchForLegend:(nonnull CPTLegend *)legend atIndex:(NSUInteger)idx inRect:(CGRect)rect inContext:(nonnull CGContextRef)context
{
id<CPTLegendDelegate> theDelegate = (id<CPTLegendDelegate>)self.delegate;
...
}
我使用的是CorePlot 2.1,我在examples/CorePlotGallery中的文件SimpleScatterPlot.m中修改了renderInGraphHostingView如下:
-(void)renderInGraphHostingView:(nonnull CPTGraphHostingView *)hostingView withTheme:(nullable CPTTheme *)theme animated:(BOOL)animated {
...
static CPTGraph *graph = nil;
if( initialize ) {
graph = [[CPTXYGraph alloc] initWithFrame:bounds];
...
}
[self addGraph:graph toHostingView:hostingView];
theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
...
}
所以每次我想绘制新的一行数据时,我都会使用相同的图表。
这个问题是随机的,有时当我画第二条线时程序崩溃,有时在第三条线,但它总是适用于第一张图。这也取决于编译。 有任何想法吗? 提前致谢
【问题讨论】: