自定义UITableViewCell,重新排序时删除初始视图

时间:2013-01-18 13:54:57

标签: ios objective-c

我有一个看起来像这样的自定义单元格

细胞

-ContainingView(称为cellframe)

- 标签

- 标签

包含视图的原因是我可以在单元格周围设置阴影。

下面是我的代码

#import "QuickNoteMasterViewCell.h"
#import <QuartzCore/QuartzCore.h>

@interface QuickNoteMasterViewCell ()

@property (nonatomic, strong) CAShapeLayer *shapeLayer;

@end



@implementation QuickNoteMasterViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

}

-(void)setEditing:(BOOL)editing{

}

// this adds shadow and border to the cell

- (void)configureBackgroundView
{
    UIView *cellFrame = self.cellFrame;
    //cellFrame.layer.borderColor = [UIColor whiteColor].CGColor;
    //cellFrame.layer.borderWidth = 10.;

    CGSize size = cellFrame.bounds.size;
    CGFloat curlFactor = 15.0f;
    CGFloat shadowDepth = 5.0f;
    cellFrame.layer.shadowColor = [UIColor blackColor].CGColor;
    cellFrame.layer.shadowOpacity = 1.f;
    cellFrame.layer.shadowOffset = CGSizeMake(.0f, 3.0f);
    cellFrame.layer.shadowRadius = 3.0f;
    cellFrame.layer.masksToBounds = NO;

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0.0f, 0.0f)];
    [path addLineToPoint:CGPointMake(size.width, 0.0f)];
    [path addLineToPoint:CGPointMake(size.width, size.height + shadowDepth)];
    [path addCurveToPoint:CGPointMake(0.0f, size.height + shadowDepth)
            controlPoint1:CGPointMake(size.width - curlFactor, size.height + shadowDepth - curlFactor)
            controlPoint2:CGPointMake(curlFactor, size.height + shadowDepth - curlFactor)];
    cellFrame.layer.shadowPath = path.CGPath;
}


- (void)layoutSubviews
{
    [super layoutSubviews];

    [self configureBackgroundView];

}



@end

before drag

问题是当我重新排序单元格时,ContainingView(称为cellframe) 被删除。

during drag

任何想法如何解决?

2 个答案:

答案 0 :(得分:0)

当重新排序UITableViewCell时,TableView将隐藏不是UILabel或UIImageView的所有内容。

不太确定为什么会这样做,但我不知道有什么办法。 我知道的唯一方法是将阴影视图创建为图像并将UIView切换为UIImageView。

抱歉!

答案 1 :(得分:0)

每当我做自定义单元格时,我都会添加自己的customView来填充整个单元格,并在该视图中执行所有绘图/自定义要求,然后您就可以完全控制。

同样在willDisplayCell上,您可以指示自定义单元格上的方法重新实现阴影等。

– tableView:willDisplayCell:forRowAtIndexPath:
相关问题