我正在使用 CCTableView 在 cocos2dx 中创建多个表格 View 。当我定义 DataSource 方法“numberOfCellsInTableView”时,我想为不同的 TableView 返回不同的值。
所以我使用了 if-control 语句。
但我似乎无法正确检查条件。
我的 CCLayer 类的 inti 方法中的代码如下:-
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));
其余定义如下:-
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;
}
以下是控制台调试日志:-
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
我不明白哪里出了问题?
最佳答案
我还在我的场景中展示了不同的表格 View ,并且我采用了不同的方法。
我创建 TableView* my_table_01 = Table_creation....
然后,我将 TAG_TABLE_01 用作 my_table_01->setTag(TAG_TABLE_01);
等其他表,更改 TAG。
在 numberOfCellsInTableView 中,我决定检查表的 TAG 的单元格数量为:
if (table->getTag() == ....) return number_cells_for_this_table;
您也可以对单元格大小使用相同的方法并拥有多个表格 View 。
关于c++ - cocos2dx : Issue when returning multiple numberOfCellsInTableView in CCTableViwe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23383910/