cocos2d-js tableView

var Cell = cc.TableViewCell.extend({
        ctor: function () {
            this._super();
            this.addChild(ccs.load(res.cell_json).node);
        },
        draw: function (ctx) {
            this._super(ctx);
        },
        getNode: function () {
            return this.children[0];
        }
    });



var tableView = new cc.TableView(this, cc.size(993, 454));
            tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
            tableView.setPosition(0, 0);
            tableView.setAnchorPoint(0, 0);
            tableView.setDelegate(this);
            $('panel.tableview').addChild(tableView);
            tableView.setName("_tableView");
            tableView.retain();
            tableView.reloadData();
            mTableView = tableView;
            this._tableView = tableView;
scrollViewDidScroll: function (view) {
        },
        scrollViewDidZoom: function (view) {
        },
        tableCellTouched: function (table, cell) {
            var idx = cell.getIdx();
            return;
        },
        tableCellTouched2: function () {
            cc.log("cell touched at index: ");
            return;
        },
        tableCellSizeForIndex: function (table, idx) {
            return cc.size(993, 93)
        },
        tableCellAtIndex: function (table, idx) {
            var cell = table.dequeueCell();
            if (!cell) {
                   //方法一
                cell = new CustomTableViewCell();

                //方法二
                cell = new cc.TableViewCell();
                var row0 = ccs.load(res.cell_json, 'res/').node;
                row0.setName('cellrow');
                cell.addChild(row0);
            }
            // 设置tableview cell的数据
        },
        numberOfCellsInTableView: function (table) {
            // return data.length;
            return data.length;
        }

mTableView 移除某一位置idx的item
mTableView.removeCellAtIndex(idx);

然后重新设置mTableView的尺寸和重置数据:
var size = mTableView.getContentSize();
mTableView.setContentSize(cc.size(size.width, size.height - 78));
mTableView.reloadData();

猜你喜欢

转载自blog.csdn.net/W_han__/article/details/87969625