首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CCBMemberVariableAssigner回调对CocosBuilder中的自定义CCTableViewCell失效

CCBMemberVariableAssigner回调对CocosBuilder中的自定义CCTableViewCell失效
EN

Stack Overflow用户
提问于 2013-04-11 15:04:03
回答 1查看 735关注 0票数 0

我的目标是通过CocosBuilder设计一个CocosBuilder,并通过CCBReader加载它。

到目前为止我的脚步:

我在cocosbuilder中添加了一个新的非全屏CCNode TestCell.ccb,将根的自定义类设置为TestCell,并在将TestCell的doc var设置为bg时添加了CCSprite作为根子。

我的问题是:在实现了加载器TestCellLoader和单元格TestCell之后,回调函数TestCell::onAssignCCBMemberVariable根本没有被调用。

我尝试过的是:到目前为止,使用CCLayerLoader而不是CCNodeLoader对我来说是有效的,这是我第一次使用CCNodeLoader,所以我可能错过了一个关键点。

谢谢,再见!本

以下是密码:

TestCellLoader.h

代码语言:javascript
复制
#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

代码语言:javascript
复制
#include "TestCellLoader.h"

CCNode * TestCellLoader::loadCCNode(CCNode * pParent, CCBReader * pCCBReader)
{
    CCLOG("TestCell::loadCCNode");
    CCNode * ccNode = this->createCCNode(pParent, pCCBReader);
    return ccNode;
}

TestCell.h

代码语言:javascript
复制
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

代码语言:javascript
复制
   #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;
         }
EN

回答 1

Stack Overflow用户

发布于 2013-04-27 12:33:18

我猜您使用了一个TestCell.ccb's根对象类型的CCLayer,因为当您创建一个新的ccb文件时,CCLayer是默认选项。

这就是为什么您使用CCLayerLoader而不是CCNodeLoader工作。

因此,将您的TestCell.ccb's根对象类型更改为CCNode,这可能有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15952273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档