cocos2d-js之tableView的一个坑,调用setTag,必须在外面要重新调用一次setTag

本文介绍了一种在Cocos2d-x中实现TableViewCell复用的方法,通过dequeueCell方法来获取可复用的单元格,并在没有可用单元格时创建新的TableViewCell。文中详细展示了如何为TableViewCell添加子节点并设置触摸事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 tableCellAtIndex:function (table, idx) {
        var cell = table.dequeueCell();
        if (!cell) {
            cell = new cc.TableViewCell();
            //创建小cell
            var pnl_cell = this.root.getChildByName("pnl_cell").clone();
            pnl_cell.setName("pnl_cell");
            pnl_cell.setPosition(cc.p(0, 0));
            pnl_cell.setVisible(true);
            cell.addChild(pnl_cell);

            var headIcon = CMF.createHeadIcon("res/icon/gem.png", "宝石");
            headIcon.setPosition(cc.p(47, 66));
            pnl_cell.addChild(headIcon);

            pnl_cell.getChildByName("btn_choose").setTag(idx);
            pnl_cell.getChildByName("btn_choose").addTouchEventListener(this.call_clickAddItem, this);
        }

        var pnl_cell = cell.getChildByName("pnl_cell");     //单元格控件
        pnl_cell.getChildByName("btn_choose").setTag(idx);  //必须重新设置tag
        return cell;
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值