当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS OC语言UITabelView自定义cell

iOS OC语言UITabelView自定义cell

2020年07月22日  | 移动技术网移动技术  | 我要评论

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

本文地址:https://blog.csdn.net/qq_45824823/article/details/107455236

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网