[Solved] CCTableView reordering rows when scrolling (bonus: TableViewButton)

Hello guys!

I’m currently using CCTableView extension to show an item shop to the player. Everything is working fine, there’s just this small “problem” that is annoying me: for some reason, when you scroll the item list, the rows gets reordered, probably because CCTableView disposes a cell when it gets out of view. Is there a way to avoid this?

I’m also leaving here my TableCellButton, a CCTableViewCell that works like a CCMenuItemSprite, you just need to use tableCellTouched, tableCellHighlight and tableCellUnhighlight from a CCTableViewDelegate like this:

void TableViewDelegate::tableCellTouched(CCTableView* table, CCTableViewCell* cell) {
	TableCellButton* t = (TableCellButton*)(cell);
	if(t) 
		t->activate();
}

void TableViewDelegate::tableCellHighlight(CCTableView* table, CCTableViewCell* cell) {
	TableCellButton* t = (TableCellButton*)(cell);
	if(t)
		t->selected();
}

void TableViewDelegate::tableCellUnhighlight(CCTableView* table, CCTableViewCell* cell) {
	TableCellButton* t = (TableCellButton*)(cell);
	if(t)
		t->unselected();
}


TableCellButton.h.zip (0.8 KB)


TableCellButton.cpp.zip (1.1 KB)

“the rows gets reordered” <-- not if you are using CCTableView the normal way.

I have sorted tables 1000 rows deep that work fine, never reorder and consume minimal memory (and render at FPS 60.)

I went and attached a debugger to the TestCpp project and saw that it does NOT re-order rows.

I can’t make heads or tails of your code, but I just wanted to point out the that you are misunderstanding the normal use case for CCTableView.

I’ve found the problem.
The sample code in TestCpp uses the same sprite every row, and just needs to update the label (if(!cell) { creates cell } else { change label only }), and I’ve copied this structure without paying much attention. Now it’s working fine.
The code I’ve shared is just a small facilitator so you can create a button-like cell (that changes images on cell pressed).
Thanks for your attention!