[Solved] trouble with CCTableView and item order

[Solved] trouble with CCTableView and item order
0.0 0



I am learning cocos2d-x and trying to use the CCTableView class to make a sliding layer with items like the TableViewTest. I have 2 bugs with the order of the cells of the tableview. I am using V2.1.4.

The items I put in my list has text with number (“Item 1” , “Item 2” etc…) and my widget is large enough to display at most 6 cells at the same time. When I have 6 items, the items appear in the right order. However when i drag the layer (the bounced option is set to true), all the items that disappeared are back in the wrong order. For instance, if i drag to make item 4 to item6 disappear, my list will be item 1 / item 2 / item 3 / item 6 / item 5 / item 4.

I could find a solution by hacking the library in the CCTableView class (only for my particular case) but if it is my code that is wrong I would prefer correct it.

Here is the hack and my code is zipped and attached to this post.

`CCTableViewCell *CCTableView::dequeueCell()
CCTableViewCell *cell;

if (m_pCellsFreed->count() == 0) {
    cell = NULL;
} else {

    int index=0;
    if(this->getDirection() == kCCScrollViewDirectionVertical && 
        m_eVordering == kCCTableViewFillTopDown )
        index = m_pCellsFreed->count() - 1;

    cell = (CCTableViewCell*)m_pCellsFreed->objectAtIndex(index);
return cell;


My other bug with items order is the following: when I am using 8 items, the displayed items starts at item 3 to item 8 instead of item 1 to item 6. Then when I drag to see the next two cells the numbers are not 7 and 8. I have no clue about that.

[edit] The answer was to use :
instead of :

Thanks for your help,

CCSlidingLayer.zip (4.4 KB)


Hello, François Cellier.

Thank you for this post.

The first bug, I was corrected.
But if you repeat the scroll many times, the items are back in the wrong order.

Is this Solved?

The second bug, where to do I fix correct?

[edit] The answer was to use :
instead of :

Thanks for reading.