2011-11-06 90 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;