2014-11-06 32 views
1

背景: 我有UITableViewCell一个子类,其布局被定义为Storyboard的原型细胞。其中一个单元的IBOutletsUIView的一个子类,我叫做BorderedProfileImageView。这个类的drawRect:功能重写如下:自定义UIView子类的drawRect不会被调用内部的UITableViewCell

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]); 
    CGContextSetLineWidth(context, 1.f); 
    CGFloat halfWidth = self.bounds.size.width/2; 
    NSInteger radius = sqrt(pow(halfWidth, 2) + pow(halfWidth, 2)) - 8.5; 
    CGContextAddArc(context,self.bounds.size.width/2,self.bounds.size.height/2,radius,0,2*3.1415926535898,1); 
    CGContextStrokePath(context); 
} 

这增加了蓝色环UIView的。

问题:
的蓝色戒指永远不会出现,并且BorderdProfileImageViewdrawRect:功能不会被调用。单元格仍然绘制,BorderdProfileImageView内部的UIImageView被绘制。设置单元格时,我确实在BorderedProfileImageView上拨打setNeedsDisplay

为什么drawRect:没有被调用?

回答

0

我想通了。

设置为BorderedProfileImageView的IB中的对象最初是UIImageView。将此对象更改为UIView并重新链接已导致所需的行为。

相关问题