我使用的是cocos2d-x 2.2.6版本,cocostudio 使用的是1.6.0.0版本,针对于UICheckBox的使用,大概代码如下:
bool HelloWorld::init() { //... UILayer* m_pUILayer = UILayer::create(); m_pUILayer->setPosition(CCPointZero); // 获取json文件 UILayout* m_pWidget = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui/UILogin.json")); m_pUILayer->addWidget(m_pWidget); this->addChild(m_pUILayer,1); // 获取UICheckBox控件 UICheckBox* m_pCheckSave = dynamic_cast<UICheckBox*>(m_pUILayer->getWidgetByName("CheckBox_Save")); // 添加事件 if(m_pCheckSave != NULL) m_pCheckSave->addEventListenerCheckBox(this,checkboxselectedeventselector(HelloWorld::selectedSaveEvent)); return true; } void HelloWorld::selectedSaveEvent( CCObject* pSender, CheckBoxEventType type ) { switch (type) { case CHECKBOX_STATE_EVENT_UNSELECTED: CCLog("You are click CHECKBOX_STATE_EVENT_UNSELECTED"); break; case CHECKBOX_STATE_EVENT_SELECTED: CCLog("You are click CHECKBOX_STATE_EVENT_SELECTED"); break; default:break; } }