I'm trying to setup a method in an external class that looks like the following:
myClass.m
- (void)drawSomeStuffInContext:(CGContextRef)context atStartingPoint:(CGPoint *)coords
{
//draw some stuff (ignoring coords for now)
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 1.0f);
CGContextMoveToPoint(context, 10, 10);
CGContextAddLineToPoint(context, 100, 50);
CGContextStrokePath(context);
}
viewController.m
- (void)viewDidLoad
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGPoint startCoords = CGPointMake(100.0, 100.0);
[[myClass alloc] drawSomeStuffInContext:currentContext atStartingPoint:startCoords];
}
The project builds and runs but I receive the following errors in the log with nothing drawn:
[...] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0
[...] <Error>: CGContextSetLineWidth: invalid context 0x0
[...] <Error>: CGContextMoveToPoint: invalid context 0x0
[...] <Error>: CGContextAddLineToPoint: invalid context 0x0
[...] <Error>: CGContextDrawPath: invalid context 0x0
I've been scouring the web for a similar question/example with no luck. Are there different/additional parameters that are required? Should I be calling the draw method from somewhere other than viewDidLoad
? Advice is much appreciated!