几种UITableview自定义Cell的办法

https://blog.csdn.net/feng2qing/article/details/51407156

1>纯代码自定义UITableviewCell

继承UITableviewCell,重写cell的initWithStyle:withReuseableCellIdentifier

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        //布局cell内部控件        [self setupUI];

    }

    return self;

}

为tableView注册cell,使用registerClass:forCellReuseIdentifier:方法注册

[_tableView registerClass:[FooterCell Class] forCellReuseIdentifier:CellIdentifier];


在cellForRowAtIndexPath中使用dequeueReuseableCellWithIdentifier:forIndexPath:获取重用的cell,若无重用的cell,将自动使用所提供的class类创建cell并返回

FooterCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

获取cell时若无可重用cell,将调用cell中的initWithStyle:withReuseableCellIdentifier:方法创建新的cell

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容