在CorePlot中崩溃CPTScatterPlotDelegate

时间:2017-01-03 16:13:35

标签: cocoa core-plot

我正在尝试在一个图中叠加多个图形,并且我在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;
       ....
    }
    ...
}

在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,我在示例/ 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];
   ...
}

因此,每次我想绘制一个新的数据线时,我都使用相同的图形。

问题是随机的,当我绘制第二行时有时程序崩溃,有时在第三行,但它总是适用于第一个图形。它还取决于编译。 有任何想法吗? 在此先感谢

1 个答案:

答案 0 :(得分:1)

delegate属性包含对委托对象的弱引用。确保在图表更新之间没有释放委托。