Custom UITableViewCell, original view is removed on reordering

I have a custom cell that looks like

Cell

-ContainingView (called cellframe)

- Label

- Label

The reason for the containing view is that I can set a shadow around the cell.

below is my code

#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

The problem is that when you change the order of the cells, the ContainingView (called the cellframe) is removed.

during drag

Any ideas how to fix it?

+3


source to share


2 answers


When the UITableViewCell is reordered, the TableView will hide anything that is not a UILabel or UIImageView.

Not really sure why he does this, but I don't know anything about it. The only way I know would be to create a shadow view as an image and switch your UIView to UIImageView.



Unfortunately!

0


source


Whenever I make custom cells, I add my own customView to fill the entire cell and fulfill all my drawing / custom requirements in that view, then you have full control.

Also on willDisplayCell you can specify your method on your custom cell to reimplement the shadow, etc.



tableView:willDisplayCell:forRowAtIndexPath:

      

0


source







All Articles