2
我使用此代码在视图中绘制一些矩形。 这是代码:为什么我在基于文档的应用程序中收到无效的上下文0x0错误?
CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);
CGContextFillRect (myContext, CGRectMake (0, 0, 200, 100));
CGContextSetRGBFillColor (myContext, 0, 0, 1, .5);
CGContextFillRect (myContext, CGRectMake (0, 0, 100, 200));
当我在一个简单的AppDelegate
使用代码,一切都还好。但是,当我(在Document.m
)任何基于文档的应用程序中使用它,我收到此错误:
<Error>: CGContextSetRGBFillColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
<Error>: CGContextSetRGBFillColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
我缺少什么?