2011-11-06 61 views
0

我有一个包含多列和几个覆盖的条形图的图形。最初,这导致了内存不足,即使它仅在Xcode仪器中显示2MB的使用量。当我拖动/滚动时,核心绘图崩溃

现在,当我尝试拖动/滚动时,它崩溃时没有任何内存通知。

我在CPTGraphHostingView中将其追溯到此方法。退出此方法后,它崩溃。

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    CGPoint pointOfTouch = [[[event touchesForView:self] anyObject] locationInView:self]; 
    if (!collapsesLayers) { 
     pointOfTouch = [self.layer convertPoint:pointOfTouch toLayer:hostedGraph]; 
    } else { 
     pointOfTouch.y = self.frame.size.height - pointOfTouch.y; 
    } 
    [hostedGraph pointingDeviceUpEvent:event atPoint:pointOfTouch]; 
} 

如果我减少了条形图的数量,它会让我拖动一些,但最终会崩溃。

其他人有类似的问题吗?

btw这是最新的代码(11/5/2011)。

+0

多少条曲线是你的图?你能从崩溃中发布错误消息和/或堆栈跟踪吗? –

+0

有42个条形图。根本没有错误消息或堆栈跟踪。屏幕在微调器上变黑并返回设备锁定屏幕。 –

+0

我在CPTGraphHostingView中的触摸代码周围放置了断点,以查看是否有特定的崩溃点。它只在touchesEnded返回后崩溃。似乎在拖动内发生了一些事情 - 可能是一些缓冲区溢出 - 导致了严重的崩溃。我无法确定这一点,因为它不会在模拟器中崩溃。 –

回答

0

collapsesLayers = YES解决了这个问题 - 谢谢埃里克。

仅供参考这是一个显示给定月份产品数量的业务图,这就是条形图数量如此之高的原因。如果有不同的方式来做到这一点,请告知。

0

,请不要使用collapsesLayers = YES如果从单个CPTGraphHostingView使得多个图表,而不是使用像这样从内存崩溃问题,以免在你cellForRowAtIndexPath方法为表视图:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GraphCell" forIndexPath:indexPath]; 
if(cell == nil) 
{ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"GraphCell"]; 
} 
for (id v in cell.contentView.subviews) 
{ 
    if ([v isKindOfClass:[CPTGraphHostingView class]]) 
    { 
     [v removeFromSuperview]; 
    } 
} 

self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:cell.contentView.bounds]; 
self.hostView.allowPinchScaling = NO; 
[cell.contentView addSubview:self.hostView]; 



/*  Configure Graph   */ 
// 1 - Create the graph 
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:CGRectMake(0, 0, 320, 180)]; 
graph.backgroundColor =[UIColor whiteColor].CGColor; 
//1].CGColor; 
self.hostView.hostedGraph = graph;