国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS開發(fā) 多個cell在初始化時注意重用池

2019-11-09 19:06:36
字體:
供稿:網(wǎng)友
多個cell在

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

方法中一定要分開來,用if或者switch,每一次上滑下拉都會調(diào)用這個方法,所以init初始化前面也必須加上

if (cell0 == nil)

來判斷,不然會init多個cell

下面是一個實例

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    if (indexPath.section == 0 && hadPublish) {        static NSString *cellIndentifier0 = @"headCell0";        HeadCurrent_View_Cell *cell0 = [tableView dequeueReusableCellWithIdentifier:cellIndentifier0];        if (cell0 == nil) {            cell0 = [[HeadCurrent_View_Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier0];        }        。。。。        return cell0;    }    else if (indexPath.section == 0 &&!hadPublish){        static NSString *cellIndentifier1 = @"headCellDefault";        UITableViewCell *cell0 = [tableView dequeueReusableCellWithIdentifier:cellIndentifier1];        if (cell0 == nil) {            cell0 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier1];
            。。。。
        }                cell0.selected = NO;        cell0.selectionStyle = UITableViewCellSelectionStyleNone;        return cell0;    }        static NSString *cellIndentifier = @"passengerOrderCell";    PassengerOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];    if (cell == nil) {        cell = [[PassengerOrderTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier];    }    。。。。    return cell;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 玉田县| 永年县| 岳普湖县| 汶川县| 扎赉特旗| 海南省| 沙雅县| 南乐县| 河曲县| 孙吴县| 济阳县| 延长县| 庄浪县| 永和县| 广丰县| 淮滨县| 长宁县| 莲花县| 泉州市| 北票市| 龙陵县| 普格县| 潜山县| 星座| 连城县| 高台县| 海阳市| 万宁市| 岑巩县| 泰顺县| 石渠县| 乌鲁木齐县| 重庆市| 鄯善县| 安义县| 本溪| 烟台市| 霍州市| 珠海市| 丰镇市| 冷水江市|