美文网首页
2018-08-08关于自定义cell

2018-08-08关于自定义cell

作者: 北你妹的风 | 来源:发表于2018-08-21 15:08 被阅读5次

这里分几种情况。

第一种情况,使用了xib。

需要在声明tableview的时候注册cell:

[tableView registerNib:[UINib nibWithNibName:@"Cell" bundle:nil] forCellReuseIdentifier:kCellIdentify];

使用cell时,调用dequeueReuseableCellWithIdentifier:forIndexPath   获取重用的cell,这里可以不判断cell为空。为空时会根据xib文件创建并调用.m文件中的awakeFromNib方法

第二种情况,没有使用xib

这种情况主要区分两个方法:dequeueReuseableCellWithIdentifier:forIndexPath和dequeueReuseableCellWithIdentifier

使用第一个方法,还需要在声明tableview注册一下,调用方法:registerClass:forCellReuseIdentifier。使用重用cell时,不需要判断cell为空。同时会调用.m文件的initWithStyle:withReuseableCellIdentifier方法

使用第二个方法,tableview不需要注册。但是在使用重用cell的时候,需要判断为空。

RecordViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"identify"];

    if(cell ==nil) {

        cell = [[RecordViewCell alloc] init];

    }

return cell

相关文章

网友评论

      本文标题:2018-08-08关于自定义cell

      本文链接:https://www.haomeiwen.com/subject/vlcjiftx.html