ios initWithFrame采坑小记

一般我们手码封装组件时 会在initWithFrame中添加自定义操作 但是重写UITableViewCell时 却不执行这个方法 需要重写initWithStyle方法

UICollectionViewCell 这样是可以的

@implementation iComeImageCollectionViewCell
#pragma mark - System
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initData];
        [self initUI];
    }
    return self;
}

UITableViewCell initWithStyle才可以

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)  {
        [self initData];
        [self initUI];
    }
    return self;
}
原文地址:https://www.cnblogs.com/lijianyi/p/11550466.html