Widget* Helper::seekWidgetByTag(Widget* root, int tag) { if (!root) { return nullptr; } if (root->getTag() == tag) { return root; } const auto& arrayRootChildren = root->getChildren(); ssize_t length = arrayRootChildren.size(); for (ssize_t i=0;i<length;i++) { Widget* child = dynamic_cast<Widget*>(arrayRootChildren.at(i)); if (child) { Widget* res = seekWidgetByTag(child,tag); if (res != nullptr) { return res; } } } return nullptr; }
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[i]); UIWidget* res = seekWidgetByTag(child,tag); if (res != NULL) { return res; } } return NULL; }