cocos2dx3.10的TableView的实现

cocos2dx3.10的TableView的实现,第1张

概述TableView就相当于Android中的ListView吧!(个人理解),就是显示一个列表相的view cpp代码 #include "HelloWorldScene.h"USING_NS_CC;USING_NS_CC_EXT;Scene* HelloWorld::createScene(){ // 'scene' is an autorelease object

tableVIEw就相当于AndroID中的ListVIEw吧!(个人理解),就是显示一个列表相的vIEw

cpp代码

#include "HelloWorldScene.h"USING_NS_CC;USING_NS_CC_EXT;Scene* HelloWorld::createScene(){    // 'scene' is an autorelease object    auto scene = Scene::create();    // 'layer' is an autorelease object    auto layer = HelloWorld::create();    // add layer as a child to scene    scene->addChild(layer);    // return the scene    return scene;}// on "init" you need to initialize your instancebool HelloWorld::init(){    //////////////////////////////    // 1. super init first    if ( !Layer::init() )    {        return false;    }    Size visibleSize = Director::getInstance()->getVisibleSize();    //tableVIEw    auto tableVIEw = tableVIEw::create(this,Size(300,500));    tableVIEw->setAnchorPoint(Point(0,0));    tableVIEw->setposition(0,0);    //注册监听事件    tableVIEw->setDelegate(this);    this->addChild(tableVIEw);    return true;}voID HelloWorld::menuCloseCallback(Ref* pSender){    Director::getInstance()->end();#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)    exit(0);#endif}

h文件

#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::Layer,public tableVIEwDataSource,public tableVIEwDelegate{public:    static cocos2d::Scene* createScene();    virtual bool init();    // a selector callback    voID menuCloseCallback(cocos2d::Ref* pSender);    // implement the "static create()" method manually    CREATE_FUNC(HelloWorld);public :    /**    * cell height for a given table.    *    * @param table table to hold the instances of Class    * @return cell size    */    virtual Size cellSizefortable(tableVIEw *table) {        return Size(300,50);    };    /** * a cell instance at a given index * * @param IDx index to search for a cell * @return cell found at IDx */    virtual tableVIEwCell* tableCellAtIndex(tableVIEw *table,ssize_t IDx)    {        tableVIEwCell* cell = table->dequeueCell();        LabelTTF * label;        if (cell == NulL)        {            cell = tableVIEwCell::create();            label = LabelTTF::create();            label->setTag(2);            label->setFontSize(30);            label->setAnchorPoint(Point(0,0));            label->setposition(0,0);            cell->addChild(label);        }        else        {            label = (LabelTTF*)cell->getChildByTag(2);        }        label->setString(StringUtils::format("Label %ld",IDx));        return cell;    }    /** * Returns number of cells in a given table vIEw. * * @return number of cells */    virtual ssize_t numberOfCellsIntableVIEw(tableVIEw *table)    {        return 100;    }public :    /**    * Delegate to respond touch event    *    * @param table table contains the given cell    * @param cell  cell that is touched    * @Js NA    * @lua NA    */    virtual voID tableCelltouched(tableVIEw* table,tableVIEwCell* cell)    {        LabelTTF * label = (LabelTTF*)cell->getChildByTag(2);        log("Lable-->%s",label->getString().c_str());    }    /** * Delegate to respond a table cell press event. * * @param table table contains the given cell * @param cell cell that is pressed * @Js NA * @lua NA */    virtual voID tableCellHighlight(tableVIEw* table,tableVIEwCell* cell){};    /** * Delegate to respond a table cell release event * * @param table table contains the given cell * @param cell cell that is pressed * @Js NA * @lua NA */    virtual voID tableCellUnhighlight(tableVIEw* table,tableVIEwCell* cell){};    /** * Delegate called when the cell is about to be recycled. Immediately * after this call the cell will be removed from the scene graph and * recycled. * * @param table table contains the given cell * @param cell cell that is pressed * @Js NA * @lua NA */    virtual voID tableCellWillRecycle(tableVIEw* table,tableVIEwCell* cell){};};#endif // __HELLOWORLD_SCENE_H__

代码不够规范,仅供交流学习使用!

总结

以上是内存溢出为你收集整理的cocos2dx3.10的TableView的实现全部内容,希望文章能够帮你解决cocos2dx3.10的TableView的实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1079512.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存