iOS开发 cell重用 封装自定义方法实现

来源:互联网 发布:用数据脱恐艾滋病 编辑:程序博客网 时间:2024/05/21 07:12

在tableview.m文件下的方法 自定义cellWithTableView方法

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    CustCarCell *cell = [CustCarCell cellWithTableView:tableView];
    
    cell.CustCar = [m_CustCarArr objectAtIndex:indexPath.row];
    
    return cell;
}


在cell.m 文件中写 如下方法

+(instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID=@"CustCarCell";
    CustCarCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell=[[CustCarCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

再截取系统的 ]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];方法

1 0
原创粉丝点击