美文网首页
TableViewCell注册及复用

TableViewCell注册及复用

作者: 小白谈理财 | 来源:发表于2018-05-09 18:54 被阅读0次

    cell提前注册两种方式:

    *  tableView registerNib:(nullable UINib *) forCellReuseIdentifier:(nonnull NSString *)
    *  tableView registerClass:(nullable Class) forCellReuseIdentifier:(nonnull NSString *)
    
    1. 系统cell和自定义代码cell
        //提前注册
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        //不提前注册
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell==nil) {
          cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        }
    
    2. 自定义cellXib注册
        //提前注册
          [self.tableView registerNib:[UINib nibWithNibName:@"xxxxViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
        xxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        //不提前注册
         xxxxCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell == nil) {
            cell=[[[NSBundle mainBundle]loadNibNamed:@“xxxxCell" owner:self options:nil]lastObject];
        }
    

    转载自:https://blog.csdn.net/zomfice/article/details/51767973

    相关文章

      网友评论

          本文标题:TableViewCell注册及复用

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