cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.18k stars 7.05k forks source link

CCTableView acting weird #2049

Closed vipsbpig closed 11 years ago

vipsbpig commented 11 years ago

when the Cells' total heigh is much shorter than TableView's heigh ,(like 1 or 2 cells )it starts acting weird . 1.touch the empty space in tableView,it callback the last cell.

  1. once I drag the cell. only drag left in DirectionHorizontal ,only drag down in FillTopDown //当cell的总高度比Table小很多的时候(例如只有1或者2 个cell),这个Tableview就变得很奇怪. 1.在TableView触摸空白的地方,它回调最后一个cell 2.只要我拖动cell ,在水平方向的模式只能往左边拖,在竖直方向只能往下拖
dumganhar commented 11 years ago

WHICH VERSION of cocos2d-x are you using? THE BUG HAS BEEN FIXED on the latest codes on the github. Did you try that?

vipsbpig commented 11 years ago

i'm using 2.0.4, maybe I should Update my cocos2d-x.

vipsbpig commented 11 years ago

drag method is working fine in last code in github code

but touch the empty space is still not work as expected ,it should be callback nothing, it still say “cell touched at index: n"

dumganhar commented 11 years ago

Thank you, i will check that.

dumganhar commented 11 years ago

Fixed at https://github.com/cocos2d/cocos2d-x/pull/2050. Could you pull the latest codes and try again? Feel free to give us your feedback. Thanks.

vipsbpig commented 11 years ago

Well,goob job!It is working fine !!

//////There is another BUG in reloaddata() function.

I use the tableView in mulit thread.The data of cell is from another thread . When I use CCTableView::create(this, CCSizeMake(size.width - 145, 196)) to create a TableView WITHOUT loading any data in another thread.
At this MOMENT numberOfCellsInTableView(cocos2d::extension::CCTableView _table) return 0 twice; after created the TableView , I load all data of cell and config the TableView ,and use pTableView->reloaddata(); numberOfCellsInTableView(cocos2d::extension::CCTableView table) return the right numberOfCell; BUT IT SHOWS NOTHING until I scoll the cell. tableCellAtIndex(cocos2d::extension::CCTableView table, unsigned int idx) only run once at the latest number. Now, I use pTableView->setContentOffset(ccp(0,(float)196-numberOfCell_50)) to calculate the right position to force it to do scroll Function to load other cell . Or has another way to load all cell?

dumganhar commented 11 years ago

When I use CCTableView::create(this, CCSizeMake(size.width - 145, 196)) to create a TableView WITHOUT loading any data in another thread.

Cocos2d-x is not thread-safe, so don't create any cocos2d-x object in another thread.

dumganhar commented 11 years ago

If you make sure that all the callings of cocos2d-x api is on the main thread. And the issue still exists. Could you add the issue test to TestCpp/TableViewTest. That will be easy for us to resolve it. Thanks.

vipsbpig commented 11 years ago

I sorry that I am not familiar with github. I just paste the code here.

// on "init" you need to initialize your instance bool TableViewTestLayer::init() { if ( !CCLayer::init() ) { return false; }

CCSize winSize = CCDirector::sharedDirector()->getWinSize();

number = 0;    // here is the code I added
CCTableView* tableView = CCTableView::create(this, CCSizeMake(250, 60));
tableView->setDirection(kCCScrollViewDirectionHorizontal);
tableView->setPosition(ccp(20,winSize.height/2-30));
tableView->setDelegate(this);
this->addChild(tableView);
number = 20;   // here is the code I added
tableView->reloadData();

number = 0 ;   // here is the code I added
tableView = CCTableView::create(this, CCSizeMake(60, 250));
tableView->setDirection(kCCScrollViewDirectionVertical);
tableView->setPosition(ccp(winSize.width-150,winSize.height/2-120));
tableView->setDelegate(this);
tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
this->addChild(tableView);
number =20;   // here is the code I added
tableView->reloadData();

// Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(TableViewTestLayer::toExtensionsMainLayer));
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero);
addChild(menuBack);

return true;

}

//and then unsigned int TableViewTestLayer::numberOfCellsInTableView(CCTableView *table) { return number; // here is the code I changed }

class TableViewTestLayer : public cocos2d::CCLayer, public cocos2d::extension::CCTableViewDataSource, public cocos2d::extension::CCTableViewDelegate { public: // etc... private: int number; };

dumganhar commented 11 years ago

OK, I will test it. Thank you.

dumganhar commented 11 years ago

Fixed at https://github.com/cocos2d/cocos2d-x/pull/2056. PLZ have a try.

vipsbpig commented 11 years ago

AWESOME!!!It solved ,I like this tableView!!!Thanks a lot!! BTW ,how to closed this issue?..

dumganhar commented 11 years ago

I closed it. You could close issue by clicking close button.