Frage

I am creating more then one tableviews in cocos2dx using CCTableView. When I define the DataSource method "numberOfCellsInTableView" i want to return different-different value for different-different TableViews.

so i used if-control statement.

but it seems i am being unable to check the condition properly.

code in my CCLayer class's inti method is as follows:-

    CCLOG("init debug 10 %d",characterImageNameArray->count());

    numberOfRowsIncharacterTable = characterImageNameArray->count();

    this->characterTable = cocos2d::extension::CCTableView::create(this,cocos2d::CCSizeMake((winSize.width/6.0)-20, winSize.height-720.0));

REST OF THE DEFINITION IS AS FOLLOWS :-

unsigned int  numberOfCellsInTableView (cocos2d::extension::CCTableView * table)
{
    CCLOG("init debug 11 ");
    int rVal = 0;
    if (table==this->characterTable) {
        CCLOG("init debug 11a ");
        rVal = this->characterImageNameArray->count();
    }
    CCLOG("init debug 12 rVal %d",rVal);
    return rVal;
}

the Following is the console debug log :-

Cocos2d: init debug 9
Cocos2d: init debug 10 6
Cocos2d: init debug 11 
Cocos2d: init debug 12 rVal 0
Cocos2d: init debug 11 
Cocos2d: init debug 12 rVal 0
Cocos2d: init debug 11 
Cocos2d: init debug 12 rVal 0

I am not getting what's gone wrong ?

War es hilfreich?

Lösung

I also present different tableviews in my scene and I follow a different approach.

I create TableView* my_table_01 = Table_creation.... Then I use TAG_TABLE_01 as my_table_01->setTag(TAG_TABLE_01); and so on for the others tables, changing the TAG.

When in the numberOfCellsInTableView I decide the number of cells checking the TAG of the table as:

if (table->getTag() == ....) return number_cells_for_this_table;

You can also use the same approach for cellsize and have multiple tableviews.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top