我有一个带有自定义backgroundView的表格视图单元格 . 此背景视图具有覆盖方法:

+ (Class)layerClass
{
    return [CAShapeLayer class];
}

在代码中,我为单元格的背景视图层指定路径,笔触颜色,填充颜色和线宽 . 接下来我尝试使用方法将section插入表视图:

- (void)insertSections:(NSIndexSet *)sections 
      withRowAnimation:(UITableViewRowAnimation)animation;

此时我得到一个错误:只有在插入动画后才会显示插入单元格的图层 . 也就是说,在动画期间,单元格没有背景和边框 .

更新:这是我为我的单元格设置自定义背景的方式:

UITableViewCell* cell = /* initializing cell */
CGRect frame = cell.frame;
frame.size.width = tableView.frame.size.width;
frame.origin = CGPointZero;
cell.backgroundView = [[MYCellBackgroundView alloc] initWithFrame:frame];
CAShapeLayer* shapeLayer = (CAShapeLayer *)cell.backgroundView.layer;

CGMutablePathRef path = CGPathCreateMutable();
/* building path with some arcs and lines  */

shapeLayer.path = path;
CGPathRelease(path);
shapeLayer.fillColor = FILL_COLOR.CGColor;
shapeLayer.strokeColor = BORDER_COLOR.CGColor;
shapeLayer.lineWidth = LINE_WIDTH;

我忘了指定我只使用CAShapeLayer来自定义单元格视图,而不是动画 .