I'm trying to implement some very simple line drawing animation for my iPhone app. I would like to draw a rectangle on my view after a delay. I'm using performSelector
to run my drawing method.
-(void) drawRowAndColumn: (id) rowAndColumn
{
int rc = [rowAndColumn intValue];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGRect rect = CGRectMake(rc * 100, 100, 100, 100);
CGContextAddRect(context, rect);
CGContextDrawPath(context, kCGPathFillStroke);
}
Which is then invoked via:
{
// ...
int col = 10;
[self performSelector:@selector(drawRowAndColumn:)
withObject: [NSNumber numberWithInt:col]
afterDelay:0.2];
}
But it seems that when the drawRowAndColumn:
message is actually sent, it no longer has access to a valid CGContextRef
, as I get errors such as:
<Error>: CGContextAddRect: invalid context
If I replace the performSelector
with a direct call to drawRowAndColumn
, it works fine. So my first idea was to also pass in the CGContextRef
via the performSelector
, but I can't seem to figure out how to pass multiple arguments at the same time (that's another good question.)
I'm a total newbie to Cocoa/iPhone/Objective-C, so I welcome constructive criticism on all aspects of this code snippet, thanks.