std::string items[] = {"1","2","3,"4","5","6","7","8","9"};
CCMenu * m_pItmeMenu = CCMenu::create();
CCSize size = CCDirector::sharedDirector()->getWinSize();
int m_nTestCount = sizeof(items) / sizeof(items[0]);
for (int i = 0; i<=m_nTestCount ;i++)
{
LabelTTF * label = LabelTTF::create(items[i].c_str(),"",20);
label->setColor(Color3B::GREEN);
MenuItemLabel * pMenuItem = MenuItemLabel::create(label,CC_CALLBACK_1(HelloWorld::menuBack,this));
m_pItmeMenu->addChild(pMenuItem,i);//i 是回调关键
pMenuItem->setPosition(CCPointMake(0,(size.height*0.5 - (i + 1) * 30)));
}
addChild(m_pItmeMenu,0,100);
回调函数
void HelloWorld::menuBack(Ref * pSender)
{
MenuItem * pMenuItem = (MenuItem *)(pSender);
int nIdx = pMenuItem->getZOrder();
}