[Resolved]CCTableView

Is there an example of CCTableView that I can use to display a list of games for the Cocos 2d HTML Framework ?

James

Please see the details in samples\tests\ExtensionsTest\TableViewTest\TableViewTestScene.js.

I’m having problems with CCTableView, my tableview doesn’t render any cell item. Any idea? I have looking for the error for almost two days, and I don’t know what is happening.

This is my code.

var CustomTableViewCell = cc.TableViewCell.extend({
    draw:function (ctx) {
        this._super(ctx);
    }
});

var VentanaPreguntar = cc.Layer.extend({
    //Variables locales
    _numeroPreguntas : null,
    _preguntas : null,

    init : function (preguntas, selSeleccionada, selCancel, sender) {

        if (!this._super()) {
            return false;
        }

        var caja;
        switch(JS.ColorActual.getColorActual()){
            case JS.ColorActual.AZUL:
                caja = cc.Sprite.createWithSpriteFrameName("ventana_preguntas2.png");
                break;
            case JS.ColorActual.ROJO:
            default:
                caja = cc.Sprite.createWithSpriteFrameName("ventana_preguntas.png");
                break;
        }
        this.addChild(caja);

        this._numeroPreguntas = preguntas.length;
        this._preguntas = preguntas;

        var winSize = cc.Director.getInstance().getWinSize();

        var tableView = cc.TableView.create(this, cc.size(60, 350));
        tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
        tableView.setPosition(cc.p(winSize.width /2, winSize.height / 2 ));
        tableView.setDelegate(this);
        tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
        this.addChild(tableView);
        tableView.reloadData();


        return true;
    },
    scrollViewDidScroll:function (view) {
    },
    scrollViewDidZoom:function (view) {
    },

    tableCellTouched:function (table, cell) {
        cc.log("cell touched at index: " + cell.getIdx());
    },

    cellSizeForTable:function (table) {
        return cc.size(60, 60);
    },

    tableCellAtIndex:function (table, idx) {
        JSLog("This happen");
        var strValue = idx.toFixed(0);
        var cell = table.dequeueCell();
        var label;
        if (!cell) {
            cell = new cc.CustomTableViewCell();
            var sprite = cc.Sprite.createWithSpriteFrameName("boton_preguntas.png");
            sprite.setAnchorPoint(cc.p(0,0));
            sprite.setPosition(cc.p(0, 0));
            cell.addChild(sprite);

            label = cc.LabelTTF.create("hello", "Helvetica", 20.0);
            label.setPosition(cc.p(0,0));
            label.setAnchorPoint(cc.p(0,0));
            label.setTag(123);
            cell.addChild(label);
            //this.addChild(cell); <-- if I add this line, I see the images, but crashes for adding two times the same child
        } else {
            label = cell.getChildByTag(123);
            //label.setString(strValue);
        }

        return cell;
    },

    numberOfCellsInTableView:function (table) {
        return 10;
    }
});

VentanaPreguntar.create = function(preguntas, selSeleccionada, selCancel, sender){
    var retObj = new VentanaPreguntar();
    if (retObj && retObj.init(preguntas, selSeleccionada, selCancel, sender)) {
        return retObj;
    }
    return null;
};

I tested my code on cocos2d-html5 v2.1.4 and v2.1.5 and get the same result

ok, I found the problem, the problem was the position of my table, was outside the visible area. :stuck_out_tongue: