次のような外部クラスでメソッドをセットアップしようとしています。
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];
}
プロジェクトはビルドおよび実行されますが、ログに次のエラーが表示され、何も描画されません。
[...] <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
私は運がない同様の質問/例を求めてウェブを精査してきました。必要な別の/追加のパラメーターはありますか? 以外の場所から draw メソッドを呼び出す必要がありviewDidLoad
ますか? アドバイスをいただければ幸いです。