关于UIWidget getChildByTag函式
这实在太坑了
底下呼叫了CCUIHELPER> seekWidgetByTag(tag);
但是会包含自己阿…
这样跟函式名称完全有误阿建议改善
UIWidget* UIHelper::seekWidgetByTag(UIWidget* root, int tag)
{
if (!root)
{
return NULL;
}
if (root->getTag() == tag)
{
return root;
}
ccArray* arrayRootChildren = root->getChildren()->data;
int length = arrayRootChildren->num;
for (int i=0;i<length;i++)
{
UIWidget* child = (UIWidget*)(arrayRootChildren->arr*);
UIWidget* res = seekWidgetByTag(child,tag);
if (res != NULL)
{
return res;
}
}
return NULL;
}
建议修改方式:
*
*
UIWidget* UIHelper::seekWidgetByTag(UIWidget parentRoot, UIWidget root, int tag)
{
if (!root)
{
return NULL;
}
if (root->getTag() == tag)
{
return root;
}
ccArray* arrayRootChildren = root->getChildren()->data;
int length = arrayRootChildren->num;
for (int i=0;i<length;i++)
{
UIWidget* child = (UIWidget*)(arrayRootChildren->arr*);
UIWidget* res = seekWidgetByTag(*parentRoot,child,tag);
-
}if (res != NULL) { return res; }
return NULL;
}
UIWidget UIWidget::getChildByTag(int tag)
{
return CCUIHELPER->seekWidgetByTag(this, this, tag);
}
getChildByName也有同样的问题
*
*