我有一個觀點在這裏面-drawRect
方法:無效的情況下爲0x0
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1.0);
for (int i=0; i<[points count]; i++) {
GraphPoint* point = [points objectAtIndex:i];
[point.color setFill];
[[UIColor blackColor] setStroke];
CGContextBeginPath(context);
CGContextAddArc(context, point.x+point.size/2, point.y+point.size/2, point.size, 0, 2*M_PI, 0);
CGContextFillPath(context);
CGContextStrokePath(context);
UIGraphicsPopContext();
}
當[points count]
等於1,一切正常驚人的,但是,當它增加,引發此錯誤:
Error>: CGContextSetStrokeColorWithColor: invalid context 0x0.
我認爲循環有問題 - 它將上下文的顏色設置了兩次甚至更多次。不知道如何避免它。每個點必須有自己的顏色,我不能在循環之前設置上下文的填充顏色。
請幫忙!也許有人曾經遇到過這個問題?
爲什麼當你不推一個時,你會彈出一個上下文? – 2012-08-13 19:12:50