Reputation: 627
i am getting this error, usually when i long press in a uitextfield and the magnifying glass appears there are many such errors reported at the same time
e.g. : CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
the only drawing code i have is as follows
what's wrong with this code
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext(); //context
CGContextBeginPath (context);
CGContextSetLineWidth(context,3);
CGPoint center = CGPointMake(rect.size.width / 2, rect.size.height / 2);//get the view centre
//get the polygon points
CGContextMoveToPoint(context, center.x-70,rect.size.height - 140 );
CGContextAddLineToPoint(context, center.x + 130, rect.size.height - 140);
CGContextAddLineToPoint(context, center.x - 70, 100);
CGContextAddLineToPoint(context, center.x- 70, rect.size.height - 140);
CGContextAddLineToPoint(context, center.x - 50, rect.size.height -140);
CGContextAddLineToPoint(context, center.x - 50, rect.size.height - 160);
CGContextAddLineToPoint(context, center.x - 70, rect.size.height - 160);
CGContextClosePath(context);//close the path
//[[UIColor clearColor] setFill];//set the colour for fill
[[UIColor blackColor] setStroke];//set the line color
CGContextDrawPath (context, kCGPathStroke);//draw
}
Upvotes: 0
Views: 1581
Reputation: 4093
Are you the one calling the drawRect:
method? You shouldn't do this, you should call setNeedsDisplay
, and the Application will call drawRect:
at the appropriate time.
If you call the drawRect:
method yourself there won't be a CGContext pushed to the context stack so the UIGraphicsGetCurrentContext()
will return nil
, and you will get the error that you're seeing.
Upvotes: 1