• 使用第三方UITableView+FDTemplateLayoutCell计算cell行高注意点


    现在很方便的计算单元格的行高大部分都是使用的第三方框架UITableView+FDTemplateLayoutCell,不知道你在使用这个框架的时候有没有遇到和我一样的问题,比如:

    在这样计算cell的高度的时候崩溃了.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        return [tableView fd_heightForCellWithIdentifier:PersonDataCellIdentify configuration:^(id cell) {
            [self configurePersonDataTableViewCell:cell atIndexPath:indexPath];
        }];
    }

    崩溃原因是必须注册cell......然后反复检查代码.

    1.自己明明都有写注册cell的代码,,identify也木有错误,就是不知道为什么崩溃;

    2.以为是cell的布局有问题,导致不能自己计算单元格的行高;

    其实原因很简单,不知道你得问题是啥,总之我的问题就是一行代码的位置问题.

    原因就是:

        self.tableView.tableFooterView = [[UIView alloc]init];这句代码在注册cell之前,导致的崩溃.
    因为你在设置表视图的tableFooterView的时候,他就会走tableView的数据源和代理方法,而这个时候你还没有注册cell,导致他认为你还没有注册cell,导致崩溃.
    #pragma mark - 设置界面
    
    - (void)setUI {
        
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, K_SCREEN_WIDTH, K_SCREEN_HEIGHT) style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.backgroundColor = [UIColor clearColor];
        self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.tableView.tableFooterView = [[UIView alloc]init];
    
        // 注册cell
    //    [_tableView registerNib:[UINib nibWithNibName:@"AddTableViewCellWithLabel" bundle:nil] forCellReuseIdentifier:ADD_LABEL_CELL_ID];
        [_tableView registerClass:[PersonDataCell class] forCellReuseIdentifier:PersonDataCellIdentify];
        [self.view addSubview:self.tableView];
    }

    解决办法就是: 先注册cell,再设置tableFooterView就好了....

    #pragma mark - 设置界面
    
    - (void)setUI {
        
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, K_SCREEN_WIDTH, K_SCREEN_HEIGHT) style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.backgroundColor = [UIColor clearColor];
        self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
        // 注册cell
    //    [_tableView registerNib:[UINib nibWithNibName:@"AddTableViewCellWithLabel" bundle:nil] forCellReuseIdentifier:ADD_LABEL_CELL_ID];
        [_tableView registerClass:[PersonDataCell class] forCellReuseIdentifier:PersonDataCellIdentify];
        self.tableView.tableFooterView = [[UIView alloc]init];
        [self.view addSubview:self.tableView];
    }

    持续记录自己在工作中遇到的问题和解决方法,希望学到更多的知识.

  • 相关阅读:
    Python--day61--Django ORM单表操作之展示用户列表
    Python--day61 PyCharm连接MySQL工具的使用
    Python--day61--ORM介绍及Django使用ORM创建表
    Python--day49--ORM框架SQLAlchemy之relationship的使用(有时间要从新看,这里状态不好,没有仔细听)
    Python--day48--ORM框架SQLAlchemy之子查询
    Python--day48--ORM框架SQLAlchemy操作表
    Python--day48--ORM框架SQLAlchemy
    Python--day48--面向对象回顾
    web api 限制单个IP在一定时间内访问次数
    前端常用js插件
  • 原文地址:https://www.cnblogs.com/pengsi/p/6571311.html
Copyright © 2020-2023  润新知