Hi All,
I have a running scene which is my home page. There is a table view (with tag MY_TABLEVIEW_TAG) inside it. It contains two cells. First cell is large which contains one item only and other is also large but contains 10 first level items. There is a first level item in second cell which contains a node with tag MY_NODE_TO_FIND. I need to find that and remove that in some scenario. For that I wrote a recursive function which returns the node with
I wrote a function to find it:
#define MY_TABLEVIEW_TAG 1003
#define MY_NODE_TO_FIND 2009
CCNode* getChildByTagRecursive(CCNode* node, int tag){
if (node->getChildByTag(tag) != NULL) {
return node;
}
auto array = node->getChildren();
CCObject* temp;
CCARRAY_FOREACH(array, temp){
CCNode* t = (CCNode*)temp;
return getChildByTagRecursive(t, tag);
}
return NULL;
}
There are many nested items are on the page. With this function I’m able to find table view with the provided tag like:
void searchNode(){
CCScene* runningScene = CCDirector::sharedDirector()->getRunningScene();
CCNode* n = getChildByTagRecursive(runningScene, MY_TABLEVIEW_TAG); //SUCCESS
//CCNode* n = getChildByTagRecursive(runningScene, MY_NODE_TO_FIND); //FAILURE
if(n != NULL) {
CCTableView* tv = (CCTableView*)n;
CCNode* mynode = getChildByTagRecursive(tv, MY_NODE_TO_FIND); // FAILURE: unable to find MY_NODE_TO_FIND, Able to find some of the nodes but all.
if (mynode != NULL) {
CCLog("--- FOUND MYNODE ---");
} else {
CCLog("COULDN'T FIND MYNODE ---");
}
} else {
CCLog("NOTHING FOUND DUDE");
}
}
I tried everything (working past 6-7 hours) but bailed to find my node.
I’m not sure if there is anything wrong withe the function “getChildByTagRecursive”. Or CCTtableView is using different data structure.
I guess, most probably there is a problem with my search method.
Can anybody help??
Thanks in advance.