UITableViewCell重用机制

    xiaoxiao2025-12-08  6

    //常用重用方式

        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //    注册原型Cell后下面方法将不会执行

        if(!cell){

            cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        }

    //第二种重用方式

        //在viewDidLoad中注册原型cell

        [self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@"CellIdentifier"];

        //使用下面方法去获得缓存cell,必须注册原型cell

        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    转载请注明原文地址: https://ju.6miu.com/read-1304730.html
    最新回复(0)