Just did a quick port of the CCMultiColumnTableView subclass of CCTableView.
>
Seems to work well on top of CCTableView extension which was recently added to Cocos2d-x 2.0.2.
>
If you already have that CCTableView extension just copy CCMultiColumnTableView + CCTableView into you folder.
>
Enjoy!
Hi Herman,
>
In fact, I already use it like CCTableView, but it seems the result is not correct. Since it is a very useful extension, why not provide a test case?
>
Anyway, I will try it again. If I still can not use it correctly, may I have you email?
Post (and describe) your problem here. Maybe some forum members can solve it, too. Currently I don’t have the time to give support for the code.
Btw since it’s a port of a Cocos2d extension - you will find the example on the net. Good luck
Following is my code. It almost same as CCTableView usage. The only difference is, I used:
pTableView~~>setColCount;
Other parts are totally same.
///////
h3. HelloWorldScene.h #ifndefHELLOWORLD_SCENE_H #defineHELLOWORLD_SCENE_H #include “cocos2d.h” #include “…/extensions/cocos-ext.h”
USING_NS_CC;
USING_NS_CC_EXT;
class HelloWorld : public CCLayer, public CCTableViewDataSource, public CCTableViewDelegate
{
public:
// Here’s a difference. Method ‘init’ in cocos2d-x returns bool, instead of returning ‘id’ in cocos2d-iphone
virtual bool init;
// there’s no ‘id’ in cpp, so we recommand to return the exactly class pointer
static CCScene* scene;
virtual void scrollViewDidScroll;
virtual void scrollViewDidZoom;
demilich husa wrote:
> Hi Herman,
>
> In fact, I already use it like CCTableView, but it seems the result is not correct. Since it is a very useful extension, why not provide a test case?
>
> Anyway, I will try it again. If I still can not use it correctly, may I have you email?
>
Post your problem here. Maybe some forum members can solve it, too. Currently I don’t have the time to give support for the code.
Btw since it’s a port of a Cocos2d extension~~ you will find the example on the net. Good luck
Would you please give some hint?
For normal case, I can create the Tableview correctly. For multipleTableView, I think the only difference is need to setColCount. Am I correct?
If you can check above code or attached code, you are appreciated.
Thanks a lot.
Herman Jakobi wrote:
demilich husa wrote:
> Hi Herman,
>
> In fact, I already use it like CCTableView, but it seems the result is not correct. Since it is a very useful extension, why not provide a test case?
>
> Anyway, I will try it again. If I still can not use it correctly, may I have you email?
>
Post (and describe) your problem here. Maybe some forum members can solve it, too. Currently I don’t have the time to give support for the code.
Btw since it’s a port of a Cocos2d extension - you will find the example on the net. Good luck
I’m using cocos2d-2.1beta3-x-2.1.0,
and if you need to get this work, you need slight change in the cocos2dx extension source code.
Basically what Herman is doing is override ‘TableCell’ positioning stuffs,
and for that he did override
@
virtual unsigned int indexFromOffset;
virtual CCPointoffsetFromIndex(unsigned int index);
virtual void _updateContentSize();
@
In Herman’s code those 3 functions does not have preceding underline(_) in function name
but in cocos2d-2.1beta3-x-2.1.0 those functions have preceding ‘_’. So change it.
And in original extension code, those 3 functions are not defined as ‘virtual’, so add ‘virtual’ keyword to those function declaration.
Now, everything is automatic.
in your old CCTableView codes, replace the creation of CCTableView to ‘CCMultiColumnTableView’.
CCMultiColumnTableView will calculate each TableCell’s position by checking each cell size via
@
CCSize cellSizeForTable(CCTableView *table)
@
and the number of cells via ‘numberOfCellsInTableView’.
I am now trying to adopt this extension to ver 2.1.4
By all means it is working with the fixes mentioned before as cocos2d-2.1rc0-x-2.1.2
But I have further checked that there is one major code difference in create function table->_updateCellPositions(); found in the original CCTableView.
I try to add it in CCMultiColumnTableView, nothing affected
I just would like to make sure if anything need to work with this to confirm there is any more I need to check
m_vCellsPositions is affected which is mainly using in the overrided functions in CCTableView only
Actually I didn’t work on it after the last message until now…
But I finally managed to use it with fixes on ver 2.2.0 (I am doing something dangerous taht I am not using the full version but just manual fixes, so it may not be that official)…
This is the final part I fix that actually no matter what direction should reset the content size, otherwise the scrolling will follow the original one
void CCMultiColumnTableView::setColCount(unsigned int cols)
{
m_colCount = cols;
if (this->getDirection() == kCCScrollViewDirectionBoth)
{
this->_updateCellPositions();
}
this->_updateContentSize();
}
And the sample code provided above has a critical error if (!pCell)
This NULL checking is necessary but it is not in that way.
… You just have to remember if it is NULL then create a new one, otherwise clear it and reuse it. If using the code above will make you confuse that the index will go wrong after a page, but seems OK if content fits in single page
I have checked under Windows and Android device only. It is working but seems the performance may not be that good especially on scrolling.
I think I have to take some time to tidy up what I have fixed in the code and a little bit testing before I am confident to share the code. If someone request I may try to push it up, otherwise I will keep up with my pace.
The whole folder of CCScrollView same as the attachment with this thread is attached. I believe you have to replace the file and do a diff to see what is changed
I just have a concern that since I am now working on a project, I just make manual replacement of some fixes in 2.1.4 with the fixes after (up to 2.2.0). Please do a checking after getting it into your project.
I found a fix in CCScrollView after 2.1.4, I don’t think it is my fix but I found it is different from the files attached with this thread. Please pay attention if you have used CCScrollView in your project.
I have added a NULL checking in several parts of CCTableView since I have to support a table with some cell is blank. Please pay attention to this if you need to make sure all cell is not blank
Before: If the cell is EMPTY the program will crash
After: The program will not crash when a cell is empty
I have done a checking in Windows and Android. Please let me know if you find weird stuff in iOS.