【发布时间】:2013-09-19 02:08:43
【问题描述】:
我试图在我的 cocos2d-x 应用程序中加入 CCTable 视图。我遵循了 testcpp 的源代码,但我仍然收到此错误,并且不是 100% 确定原因
"分配抽象类类型'GameList'的对象"
这是我的源代码
GameList.h
#ifndef __Squares__GameList__
#define __Squares__GameList__
#include "cocos2d.h"
#include "cocos-ext.h"
#include "GameListScene.h"
#include "GameManager.h"
using namespace cocos2d;
class GameList : public CCLayer, public extension::CCTableViewDataSource, public extension::CCTableViewDelegate
{
public:
virtual bool init();
CREATE_FUNC(GameList);
~GameList(void);
CCLabelTTF* titleLabel;
CCLabelTTF* loginLabel;
CCLabelTTF* passwordLabel;
virtual void tableCellTouched(extension::CCTableView* table, extension::CCTableViewCell* cell);
virtual CCSize tableCellSizeForIndex(extension::CCTableView *table, unsigned int idx);
virtual unsigned int numberOfCellsInTableView(extension::CCTableView *table);
};
#endif
游戏列表.cpp
USING_NS_CC;
USING_NS_CC_EXT;
bool GameList::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCTableView* tableView = CCTableView::create(this, CCSizeMake(250, 60));
tableView->setDirection(kCCScrollViewDirectionHorizontal);
tableView->setPosition(ccp(20,size.height/2-30));
tableView->setDelegate(this);
this->addChild(tableView);
tableView->reloadData();
return true;
}
GameList::~GameList(void)
{
}
void GameList::tableCellTouched(CCTableView* table, CCTableViewCell* cell)
{
CCLOG("cell touched at index: %i", cell->getIdx());
}
CCSize GameList::tableCellSizeForIndex(CCTableView *table, unsigned int idx)
{
return CCSizeMake(60, 60);
}
unsigned int GameList::numberOfCellsInTableView(CCTableView *table)
{
return 20;
}
任何帮助将不胜感激
谢谢
【问题讨论】:
-
这不是问题,但是包含两个连续下划线的名称(
__Squares__GameList__,带有报复性)和以下划线后跟大写字母的名称保留给实现。不要使用它们。 -
那些是在我创建每个新文件时创建的。
-
然后你需要重新配置你正在使用的任何工具来生成这些东西。它们是保留名称。不要使用它们。
标签: c++ uitableview cocos2d-x