美文网首页
iOS 注册cell

iOS 注册cell

作者: 夏天爱西瓜汁 | 来源:发表于2017-11-28 11:23 被阅读48次

    2016.4.14

    1.自定义cell时,

    若使用nib,使用 registerNib: 注册,dequeue时会调用 cell 的 -(void)awakeFromNib

    不使用nib,使用 registerClass: 注册, dequeue时会调用 cell 的 - (id)initWithStyle:withReuseableCellIdentifier:

    文/XiaXiang(简书作者)

    原文链接:http://www.jianshu.com/p/66420a87b844

    著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

    使用dequeueReuseableCellWithIdentifier:可不注册,但是必须对获取回来的cell进行判断是否为空,若空则手动创建新的cell;

    if(cell ==nil) {

    cell = [[PreSallDetailCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cellid"];

    }

    使用dequeueReuseableCellWithIdentifier:forIndexPath:必须注册,但返回的cell可省略空值判断的步骤。

    xib:

    [_tableView registerNib:[UINib nibWithNibName:@"xxxxxCell" bundle:nil] forCellReuseIdentifier:kCellIdentify];

    xxxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentify forIndexPath:indexPath];

    代码

    [_tableView registerClass:[xxxxxCell class] forCellReuseIdentifier:kCellIdentify];

    xxxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentify forIndexPath:indexPath];

    相关文章

      网友评论

          本文标题:iOS 注册cell

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