OK, so you are calling drawRect or the code that you showed directly. You can't do that. To make a view draw itself send setNeedsDisplay. Update whatever state the view needs to draw itself and then send setNeedsDisplay.
You can't draw to a view outside drawRect and you can't call drawRect directly.
The invalid context that is mentioned in the error messages is the CGContext that is required for all drawing. When the framework calls a view's drawRect method it first sets up this context.
|