/* Adding the Path */
UserGraphBuff = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(UserGraphBuff,5,10,0,1);
CGContextSetLineWidth(UserGraphBuff, 2);
CGContextBeginPath(UserGraphBuff);
//line to last user point
CGContextAddLineToPoint(UserGraphBuff, (*xVal)[sizeof xVal/sizeof *xVal - 1], (*yNewVal)[sizeof yNewVal/sizeof *yNewVal - 1]);
//line to rest of user points in reverse order
for (int i = sizeof xVal/sizeof *xVal - 1; i > -1; i--){
CGContextAddLineToPoint(UserGraphBuff, (*xVal)[i], (*yNewVal)[i]);
}
//EOFill
CGContextEOFillPath(UserGraphBuff);
以上是我正在尝试通过的代码。它应该做什么CGContext说它做,但我没有得到任何东西绘制。 我不断收到此错误:使用CGContext *功能时出现'无效上下文0x0'错误
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextSetRGBStrokeColor: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextSetLineWidth: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextBeginPath: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextAddLineToPoint: invalid context 0x0
Fri Oct 28 13:18:40 case.app testApplication[4127] <Error>: CGContextDrawPath: invalid context 0x0
我引用CGContextRef在我的头文件。
我不认为我很了解CGContext,也不知道CGContextRef应该是什么。
此代码位于何处?在UIView子类的'drawRect'中? – MusiGenesis
' - (void)userShow {' –
那是什么?它有什么作用?它是否被'-drawRect:'调用? –