I am trying to change the text of a CCLabelTTF in cocos2d xcode (objective-c). I am setting the label like this:
CCLabelTTF *progressLBL = [CCLabelTTF labelWithString:@"connecting..." fontName:@"Marker Felt" fontSize:10];
progressLBL.position = ccp( width + 4, (s.height) - hight - 15);
CCMenu *menuHolder = [CCMenu menuWithItems:publishingLinesButton , nil];
[self addChild:progressLBL z:10 tag:cnt];
s is just the hight and width of the screen and cnt if an integer that goes up each time from 1 to 13. Then about 5 seconds after the label is created i get it like this:
CCLabelTTF *progressLBL = (CCLabelTTF *)[self getChildByTag:[dataInfo objectAtIndex:0]];
progressLBL.string = @"Updated";
dataInfo is an array and the object at index 0 is an integer. However when i run this code the labels are not changed. I have also tried:
CCLabelTTF *progressLBL = (CCLabelTTF *)[self getChildByTag:4];
But still the label is not changed.
Thanks, Sorry for wasting your time if this is something supper simple.
The fact is that an Objective-C array contains objects, it cannot contain primitive types. The tag argument is an integer, and you're passing an object instead (probably you got a compiler warning). I suppose that the object is a NSNumber, so you should take it's value calling the intValue accessor:
CCLabelTTF *progressLBL = (CCLabelTTF *)[self getChildByTag:[dataInfo objectAtIndex:0].intValue ];
Which with the newer compilers syntax can be translated like this:
CCLabelTTF *progressLBL = (CCLabelTTF *)[self getChildByTag: dataInfo[0].intValue ];