【问题标题】:crash on CPTScatterPlotDelegate in CorePlot在 CorePlot 中的 CPTScatterPlotDelegate 上崩溃
【发布时间】: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];
   ...
}

所以每次我想绘制新的一行数据时,我都会使用相同的图表。

这个问题是随机的,有时当我画第二条线时程序崩溃,有时在第三条线,但它总是适用于第一张图。这也取决于编译。 有任何想法吗? 提前致谢

【问题讨论】:

    标签: cocoa core-plot


    【解决方案1】:

    delegate 属性持有对委托对象的弱引用。确保代理在图更新之间没有被释放。

    【讨论】:

    • Eric,谢谢我每次尝试创建新图形时不小心创建了 SimpleScatterPlot 类的多个副本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 2018-11-01
    • 1970-01-01
    • 2012-07-16
    相关资源
    最近更新 更多