No sort of curve shows up on the screen. Also whenever I called drawRect: directly from the appDelegate it gave me a bunch of errors about invalid contexts. Can anybody tell what I'm doing wrong?
What I'm trying to achieve is a white square with a black outline. The black outline is showing up okay, but the white fill isn't there. It's also giving me
Code:
<Error> CGContextBeginPath: invalid context 0x0
for each time I use CGContext. I don't know why, because the square is showing up anyway. Please help me get my background and get rid of these <Errors>!
I'm not sure about the invalid context error, but the problem with the fill not showing up is because the CGContext's current path is cleared as soon as it's filled or stroked. That means you can't call CGContextFillPath after you've already called CGContextStrokePath, as the path as already been cleared by then.
The simplest fix is just to use CGContextDrawPath to fill and stroke the path in one call:
Code:
CGContextDrawPath(context, kCGPathFillStroke);
In general, if you want to draw the same path multiple times, you need to explicitly create a CGPath using CGPathCreateMutable and then add it to the current context when you're ready to draw it with CGContextAddPath. See the section on paths in the Quartz 2D Programming Guide for more info.