2012-10-21 2 views
0

UITableViewCell에 CABasicAnimation이 포함 된 사용자 지정 UIView를 추가하려고합니다. 다음과 같은 화면이 보여 나는이에게 다음과 같은 방법UITableView addsubview Crahes

if(self.pie_chart_view == nil) 
    self.pie_chart_view = [[PieChartView alloc] initWithFrame:CGRectMake(0.f, 0.f, 30.f, 30.f)]; 
[pie_chart_view animate_progress_from:0.0 to:1.0 with_duration:5.0]; 
[cell.contentView addSubview:pie_chart_view]; 

하지만 코드 충돌을 수행

enter image description here

충돌 분명히 코드

- (void)drawInContext:(CGContextRef)context { 
CGRect circleRect = CGRectInset(self.bounds, 1, 1); 

CGColorRef borderColor = [[UIColor whiteColor] CGColor]; 
CGColorRef backgroundColor = [[UIColor colorWithWhite:0 alpha: 0.75] CGColor]; 

CGContextSetFillColorWithColor(context, backgroundColor); <--- CRASHES ON THIS LINE WITH EXC_BAD_ACCESS 
CGContextSetStrokeColorWithColor(context, borderColor); 
CGContextSetLineWidth(context, 2.0f); 

CGContextFillEllipseInRect(context, circleRect); 
CGContextStrokeEllipseInRect(context, circleRect); 

CGFloat radius = MIN(CGRectGetMidX(circleRect), CGRectGetMidY(circleRect)); 
CGPoint center = CGPointMake(radius, CGRectGetMidY(circleRect)); 
CGFloat startAngle = -M_PI/2; 
CGFloat endAngle = self.progress * 2 * M_PI + startAngle; 
CGContextSetFillColorWithColor(context, borderColor); 
CGContextMoveToPoint(context, center.x, center.y); 
CGContextAddArc(context, center.x, center.y, radius, startAngle, endAngle, 0); 
CGContextClosePath(context); 
CGContextFillPath(context); 

[super drawInContext:context]; 
} 

의 다음 부분에서 발생 그러나 왜 충돌해야하는지 모르겠다. 내 프로젝트는 ARC를 사용합니다. 내가 여기서 무엇을 놓치고 있니?

답변

0

좋아요, 문제를 해결했습니다. ARC를 사용하면 UIColor가 즉시 삭제됩니다. 다음 중 하나를 수행하여이를 복구 할 수 있습니다.

UIColor * __autoreleasing borderColor = [UIColor whiteColor]; 
UIColor * __autoreleasing backgroundColor = [UIColor colorWithWhite:0 alpha: 0.75]; 

CGContextSetFillColorWithColor(context, backgroundColor.CGColor); 
CGContextSetStrokeColorWithColor(context, borderColor.CGColor); 

그런 다음 코드가 더 이상 충돌하지 않습니다.