在 CorePlot 中的 CPTScatterPlotDelegate 上崩溃
crash on CPTScatterPlotDelegate in CorePlot
我试图在一个图中叠加多个图表,但我在下面 class CPTScatterPlot.m
中的 CPTScatterPlotDelegate 上遇到崩溃(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;
....
}
...
}
在 class 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];
...
}
所以每次我想绘制新的一行数据时,我都使用相同的图表。
这个问题是随机的,当我画第二条线时有时程序崩溃,有时在第三条线时程序崩溃,但它总是适用于第一张图。这也取决于编译。
有任何想法吗?
提前致谢
delegate
属性 持有对委托对象的弱引用。确保委托未在图更新之间被释放。
我试图在一个图中叠加多个图表,但我在下面 class CPTScatterPlot.m
中的 CPTScatterPlotDelegate 上遇到崩溃(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;
....
}
...
}
在 class 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];
...
}
所以每次我想绘制新的一行数据时,我都使用相同的图表。
这个问题是随机的,当我画第二条线时有时程序崩溃,有时在第三条线时程序崩溃,但它总是适用于第一张图。这也取决于编译。 有任何想法吗? 提前致谢
delegate
属性 持有对委托对象的弱引用。确保委托未在图更新之间被释放。