cocos2d-x 2.2.2 기준.
CCTableView는 실제 리스트 기능을 하는 CCScrollView와 스크롤 이벤트 인터페이스
와 CCScrollViewDelegate로 구성된다.
class CCTableView : public CCScrollView, public CCScrollViewDelegate
# 생성하기
CCTableView* CCTableView::create(CCTableViewDataSource* dataSource, CCSize size)
{
return CCTableView::create(dataSource, size, NULL);
}
CCTableView* CCTableView::create(CCTableViewDataSource* dataSource, CCSize size, CCNode *container)
{
CCTableView *table = new CCTableView();
table->initWithViewSize(size, container);
table->autorelease();
table->setDataSource(dataSource);
table->_updateCellPositions();
table->_updateContentSize();
return table;
}
뒷부분에 CCNode *container 를 추가하면, 별도의 레이어를 생성한 후에, addChild하도록 되어있음.
bool CCScrollView::initWithViewSize(CCSize size, CCNode *container/* = NULL*/)
{
if (CCLayer::init())
{
m_pContainer = container;
if (!this->m_pContainer)
{
m_pContainer = CCLayer::create();
this->m_pContainer->ignoreAnchorPointForPosition(false);
this->m_pContainer->setAnchorPoint(ccp(0.0f, 0.0f));
}
this->setViewSize(size);
setTouchEnabled(true);
m_pTouches = new CCArray();
m_pDelegate = NULL;
m_bBounceable = true;
m_bClippingToBounds = true;
//m_pContainer->setContentSize(CCSizeZero);
m_eDirection = kCCScrollViewDirectionBoth;
m_pContainer->setPosition(ccp(0.0f, 0.0f));
m_fTouchLength = 0.0f;
this->addChild(m_pContainer);
m_fMinScale = m_fMaxScale = 1.0f;
m_mapScriptHandler.clear();
return true;
}
return false;
}