UITableViewCells尝试绘制无效上下文

我想在UITableViewCell中绘制一个checkbox三angular形。 在数据源协议方法-tableView:cellForRowAtIndexPath:我已经在代码块中添加了以下内容,询问单元格是否为零:

CGContextRef context = UIGraphicsGetCurrentContext(); CGContextBeginPath(context); CGContextMoveToPoint(context, 75,10); CGContextAddLineToPoint(context, 10, 150); CGContextAddLineToPoint(context, 160, 150); CGContextClosePath(context); [[UIColor blackColor] setStroke]; CGContextStrokePath(context); 

执行代码时,我得到了一系列'无效的上下文0x0'消息在以下方法:CGContextBeginPath:CGContextMoveToPoint:CGContextAddLineToPoint:(两次)CGContextClosePath:CGContextSetStrokeColorWithColor:CGContextDrawPath

消息重复我的表中的每个TableViewCell行。

我无法在customizedUITableViewCell对象内绘制三angular形或其他几何形状吗?

如果在drawRect:外调用, UIGraphicsGetCurrentContext()将不会返回有效的上下文。 您必须在视图的drawRect:方法中执行自定义绘图。 为了您的目的,您应该为您的checkbox创build一个自定义的UIView子类,并将该视图作为子视图添加到单元格中。