美文网首页
UITableViewCell 注册与不注册

UITableViewCell 注册与不注册

作者: benzhaoguo | 来源:发表于2017-12-27 09:55 被阅读0次

    1.tableView registerNib:(nullable UINib *) forCellReuseIdentifier:(nonnull NSString *)

    2.tableView registerClass:(nullable Class) forCellReuseIdentifier:(nonnull NSString *)

    Cell注册的形式:

    (1)系统cell

        1.注册

        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

        2.不注册

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

      if (cell == nil) {

          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

        }

    (2)自定义cell

        1.注册

        [self.tableView registerClass:[xxxxCell class] forCellReuseIdentifier:@"cell"];

        xxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

      2.不注册

        xxxxCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];

      if (cell==nil) {

          cell=[[xxxxCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

    (3)自定义cellXib注册

        1.注册

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

        xxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

        2.不注册

        xxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

        if (cell == nil) {

            cell = [[[NSBundle mainBundle]loadNibNamed:@“xxxxCell" owner:self options:nil]lastObject];

        }

    相关文章

      网友评论

          本文标题:UITableViewCell 注册与不注册

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