ios – 无法在UITableViewCell的drawRect中绘制

我在使用自定义UITableViewCell的drawRect方法时遇到了麻烦.这是我正在使用的代码
- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx  = UIGraphicsGetCurrentContext();
    CGPoint origin    = _faceView.frame.origin;
    CGFloat width     = _faceView.frame.size.width;
    CGFloat height    = _faceView.frame.size.height;
    CGFloat border    = 2.0f;


    CGPoint startPt   = CGPointMake(origin.x + width/2,self.frame.size.height);
    CGContextBeginPath(ctx);
    CGContextMovetoPoint(ctx,startPt.x,startPt.y);

    CGPoint basePt    = CGPointMake(startPt.x,origin.y - height - border);
    CGContextAddLinetoPoint(ctx,basePt.x,basePt.y);

    CGRect circleRect = CGRectMake(origin.x - border,origin.y - border,width + 2 * border,height + 2 * border);
    CGContextAddEllipseInRect(ctx,circleRect);

    UIColor *color = [UIColor redColor];
    CGContextSetFillColorWithColor(ctx,color.CGColor);
    CGContextSetstrokeColorWithColor(ctx,color.CGColor);
    CGContextSetlinewidth(ctx,1.0f);

    CGContextDrawPath(ctx,kCGPathFillstroke);
}

我已经调试过以确保所有数值都有意义,看起来它们确实存在.无法真正找出屏幕上没有任何内容的原因.

值得一提的是,这也是一个在笔尖中定义的单元格.我正在使用iOS 7 sdk构建.

有任何想法吗?

tahnks

解决方法

你可能不应该在UITableViewCell自己的drawRect中这样做.而是创建一个自定义UIView并将其添加为子视图.

另见this answer.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...