Added Method to create a CCMenuItemToggle from a CCArray with a target selector.

This commit is contained in:
Paras Mendiratta 2013-03-12 12:41:41 +05:30
parent 2be1347dc7
commit 94a5cdad29
2 changed files with 21 additions and 0 deletions

View File

@ -714,6 +714,24 @@ CCArray* CCMenuItemToggle::getSubItems()
return m_pSubItems; return m_pSubItems;
} }
CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems)
{
CCMenuItemToggle *pRet = new CCMenuItemToggle();
pRet->CCMenuItem::initWithTarget(target, selector);
pRet->m_pSubItems = CCArray::create();
pRet->m_pSubItems->retain();
for (int z=0; z < menuItems->count(); z++)
{
CCMenuItem* menuItem = (CCMenuItem*)menuItems->objectAtIndex(z);
pRet->m_pSubItems->addObject(menuItem);
}
pRet->m_uSelectedIndex = UINT_MAX;
pRet->setSelectedIndex(0);
return pRet;
}
CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...) CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...)
{ {
va_list args; va_list args;

View File

@ -322,6 +322,9 @@ public:
, m_pSubItems(NULL) , m_pSubItems(NULL)
{} {}
virtual ~CCMenuItemToggle(); virtual ~CCMenuItemToggle();
** creates a menu item from a CCArray with a target selector */
static CCMenuItemToggle * createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems);
/** creates a menu item from a list of items with a target/selector */ /** creates a menu item from a list of items with a target/selector */
static CCMenuItemToggle* createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...); static CCMenuItemToggle* createWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, ...);