1

我创建了一个具有 CAGradiantLayer 背景的表视图。然后我在 TableViewCell 中创建了标签并给它们标签。现在是我的问题,滚动后的下一个单元格不会出现。似乎下一个单元格正在过度绘制或没有从 UITableViewCell 的子类中获取属性。但是出现了一个单元格之后的单元格。如果我删除 bgLayer 它可以工作。我不知道为什么。

这是 UITableView 的子类

- (void)drawRect:(CGRect)rect
{
    NSArray *count = [Elements getElements];
    CGFloat height = count.count * 44;
    CGRect newRect = rect;
    CAGradientLayer *bgLayer = [BGLayer getGreyGradient];
    newRect.size.height = height;
    bgLayer.frame = newRect;
    [self.layer insertSublayer:bgLayer atIndex:0];

这来自 UITableViewCell

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    UIView *bg = [[UIView alloc] init];
    self.opaque = NO;
    self.backgroundColor = [UIColor clearColor];
    if(selected)
    {
        bg.backgroundColor = [UIColor redColor];
        [self setBackgroundView:bg];

        // cell mit tags von 100 - 106
        for(NSInteger i=100; i<107; i++)
        {
            UILabel *str = (UILabel *)[self viewWithTag:i];
            str.textColor = [UIColor whiteColor];
        }
    }
    else
    {
        bg.backgroundColor = [UIColor clearColor];

        [self setBackgroundView:bg];
        for(NSInteger i=100; i<107; i++)
        {
            UILabel *str = (UILabel *)[self viewWithTag:i];
            str.textColor = [UIColor blackColor];
        }
    }
    [super setSelected:selected animated:animated];

感谢帮助

4

0 回答 0