Обратные вызовы CCBMemberVariableAssigner не работают для пользовательских CCTableViewCell в CocosBuilder
Моя цель - спроектировать CCTableViewCell через CocosBuilder и загрузить его через CCBReader.
Мои шаги до сих пор:
Я добавил новый не полноэкранный CCNode TestCell.ccb в cocosbuilder, установил пользовательский класс root в TestCell
и добавил CCSprite в качестве дочернего элемента root при установке его doc-root-var в bg
,
Моя проблема: после реализации загрузчика TestCellLoader
а также клетка TestCell
функция обратного вызоваTestCell::onAssignCCBMemberVariable
не называется вообще.
Что я пробовал: используя CCLayerLoader
вместо CCNodeLoader
до сих пор работал на меня, это первый раз, когда я использую CCNodeLoader
так что, возможно, я упустил важный момент.
Спасибо, Чао! Бен
Вот коды:
TestCellLoader.h
#include <cocos2d.h>
#include "cocos-ext.h"
#include "TestCell.h"
using namespace cocos2d;
using namespace cocos2d::extension;
class TestCellLoader : public CCNodeLoader
{
public:
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(TestCellLoader, create);
protected:
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(TestCell);
virtual CCNode* loadCCNode(CCNode *, CCBReader * pCCBReader);
};
TestCellLoader.cpp
#include "TestCellLoader.h"
CCNode * TestCellLoader::loadCCNode(CCNode * pParent, CCBReader * pCCBReader)
{
CCLOG("TestCell::loadCCNode");
CCNode * ccNode = this->createCCNode(pParent, pCCBReader);
return ccNode;
}
TestCell.h
class TestCell : public CCTableViewCell, public CCNodeLoaderListener, public CCBMemberVariableAssigner
{
public:
TestCell();
virtual ~TestCell();
static TestCell *create();
virtual bool init();
virtual bool initWithBG(CCSprite* bg);
static TestCell* cellWithBG(CCSprite* bg);
// ccbuilder callbacks
virtual bool onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, const char * pMemberVariableName, cocos2d::CCNode * pNode);
virtual void onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader);
private:
CC_PROPERTY(CCSprite*, bg, Bg);
};
TestCell.m
#include "TestCell.h"
using namespace cocos2d;
using namespace cocos2d::extension;
TestCell::TestCell(){}
TestCell::~TestCell(){}
#pragma mark creation
TestCell* TestCell::create(){
TestCell *pRet = new TestCell();
pRet->init();
pRet->autorelease();
return pRet;
}
bool TestCell::init(){
return true;
}
bool TestCell::initWithBG(CCSprite* bg){
return true;
}
TestCell* TestCell::cellWithBG(CCSprite* bg){
return new TestCell;
}
#pragma mark - synthesize
void TestCell::setBg(cocos2d::CCSprite *sprite){
this->bg = sprite;
}
CCSprite* TestCell::getBg(){
return this->bg;
}
#pragma mark - ccbuilder callbacks
void TestCell::onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader)
{
CCLOG("TestCell::onNodeLoaded");
}
bool TestCell::onAssignCCBMemberVariable(CCObject* pTarget, const char* pMemberVariableName, CCNode* pNode)
{
CCLOG("TestCell::onAssignCCBMemberVariable %s", pMemberVariableName);
return false;
}
1 ответ
Я думаю, что вы использовали CCLayer
как тип корневого объекта TestCell.ccb. Так как, когда вы создаете новый файл ccb, CCLayer
по умолчанию.
И именно поэтому вы используете CCLayerLoader
вместо CCNodeLoader
работал.
Поэтому измените тип объекта Root вашего TestCell.ccb на CCNode
это может работать.