I'm trying to draw some bezier paths in my view's drawRect method, but I keep getting an invalid context error. I don't understand why, because I thought that there was always a context when drawRect is called. Am I missing something? This is the full implementation I have:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat pattern[] = {5.0, 3.0};
CGContextSetLineDash(context, 0.0, pattern, 2);
// Set line color to be black
[[UIColor blackColor] setStroke];
//Stroke the bezier path for each plane
for(SEPlaneView *plane in self.planes){
// Set line thickness and termination style
[plane.planeBezier setLineWidth:1.0];
[plane.planeBezier setLineCapStyle:kCGLineCapRound];
[plane.planeBezier stroke];
}
CGContextRelease(context);
}